PDA

View Full Version : Korean font currupting



bhaskar
19th February 2010, 05:58
Dear All,
First i shd say , thanks to all people for sharing knowledge each other in this forum.


I am having one problem for unsigned char * string changed to QString korean font is currupting.

char* BConvertToMultiByte(unsigned short* pStrIn, int nSize)
QTextCodec* pCodec = NULL;
pCodec = QTextCodec::codecForName("EUC-KR"); break;
unsigned short* pSrc = pStrIn;
QString temp;
while( *pSrc )
{
temp += QChar(*pSrc);
pSrc++;

}
QByteArray strOut= pCodec->fromUnicode(temp);
return strOut.data();

This return value collecting as a unsigned char * strTemp;
strTemp if i print this its printing correct charectors in korea
QString qstrVal((char *) strTemp);
qstrVal if i print its comming different charectors, its hex values also different from strTemp hex values.
I have tried different encodingings like
QTextCodec::codecForName("EUC-KR");
QTextCodec::codecForName("utf8");
unicode convertion, like pCodec->fromUnicode(),pCodec->fromAscii... so many methods which are available in QTextcodec and QString functionlities.

So please can any one tell me how to get proper font charectors...

before showing to UI also i am printing this charectors its not similar...



Thanks in advance...

Bhaskar.kotha



I tried doing

psih128
19th February 2010, 07:41
Hi. Have you tried doing simply

QString str = QString::fromUtf8(pStrIn)

I think in your code the corruption occurs when you add character one by one in the loop:

temp += QChar(*pSrc);
pSrc is a pointer to unsigned short, but multibyte encoding has variable width, and you end up corrupting the data, because some character use more or less memory that an unsigned short uses. I might be wrong on this statement - i'm not good with encodings.

bhaskar
22nd February 2010, 01:02
Hi. Have you tried doing simply

QString str = QString::fromUtf8(pStrIn)

I think in your code the corruption occurs when you add character one by one in the loop:

temp += QChar(*pSrc);
pSrc is a pointer to unsigned short, but multibyte encoding has variable width, and you end up corrupting the data, because some character use more or less memory that an unsigned short uses. I might be wrong on this statement - i'm not good with encodings.


Hi,
Thanks for ur replay..

i) I have tried doing QString str = QString::fromUtf8(pStrIn) with this still its crashing the system ...
ii). After doing temp += QChar(*pSrc); this i am able to print string properly when in my use function that time when i am converting to unsigned char * to Qstring its crashing.
onemore i have to clear is clear my input string is having engish and korean charector mix...
And How can we find what ocale we r using in environment, And how to over come this unsigned char* to Qstring font curruption issue..