PDA

View Full Version : convert from unsigned char* to QString



bhaskar
12th February 2010, 02:01
Dear All,
I have problem for font issue when i convert from unsoigned char * to QString.

pMedia->pLinkPath this is unsigned char *
QString tmpStr;
QTextCodec *utf8Codec = QTextCodec::codecForName("eucKR");
tmpStr = utf8Codec->toUnicode((char *)pMedia->pLinkPath)
for english font is ok but for korean font font is currupting.

tmpStr.sprintf("%s",pMedia->pLinkPath);
tried this way also same problem...
plz can any one help...

Coises
12th February 2010, 04:24
QTextCodec *utf8Codec = QTextCodec::codecForName("eucKR");

This is just a wild guess, but the naming suggests it. You call the codec utf8Codec but set it up to decode EUC-KR. Those two encodings are not the same. Are you sure the source is EUC-KR and not UTF-8?


for english font is ok but for korean font font is currupting

It might be worth printing the string in hexadecimal form so you can check to see if it’s the string that isn’t what you expect, or if the problem has something to do with the font or the way it’s being used. (If there’s a simple way to print out in hexadecimal, I don’t see it; I think you have to loop through the string one character at a time, something like this:


QString hexprint = "";
for (int i = 0; i < tmpStr.length(); ++i) hexprint += QString("%1 ").arg((unsigned short) (tmpStr[i]), 4, 16, '0');

to get a printable string in hexadecimal.)

bhaskar
12th February 2010, 06:36
Hi Coises,
Thank you for ur support..

I tried using EUC-KR and UTF-8, 16 all encoding names...

Before i get source unsigned char i am getting like

unsigned short* pStrIn ----- this is input
int nSize,
char* pOutput;

unsigned short* pSrc = pStrIn;
QString temp;

while( *pSrc ){ temp += QChar(*pSrc);
pSrc++;}

pCodec = QTextCodec::codecForName("EUC-KR");
QByteArray strOut= pCodec->fromUnicode(temp);
memcpy(pOutput, strOut.data(), strOut.size());
this pOutput i am getting as a unsigned char * to my function.

In my function i am doing

unsoigned char * to QString.

pMedia->pLinkPath this is unsigned char *
QString tmpStr;
QTextCodec *utf8Codec = QTextCodec::codecForName("eucKR");
tmpStr = utf8Codec->toUnicode((char *)pMedia->pLinkPath)
for english font is ok but for korean font font is currupting.

tmpStr.sprintf("%s",pMedia->pLinkPath);

when i am printing hex values that hex values also getting different for some charector.