Results 1 to 3 of 3

Thread: convert from unsigned char* to QString

  1. #1
    Join Date
    Feb 2010
    Location
    New delhi
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question convert from unsigned char* to QString

    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...

  2. #2
    Join Date
    Nov 2009
    Posts
    129
    Thanks
    4
    Thanked 29 Times in 29 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: convert from unsigned char* to QString

    Quote Originally Posted by bhaskar View Post
    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?

    Quote Originally Posted by bhaskar View Post
    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:
    Qt Code:
    1. QString hexprint = "";
    2. for (int i = 0; i < tmpStr.length(); ++i) hexprint += QString("%1 ").arg((unsigned short) (tmpStr[i]), 4, 16, '0');
    To copy to clipboard, switch view to plain text mode 
    to get a printable string in hexadecimal.)

  3. #3
    Join Date
    Feb 2010
    Location
    New delhi
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: convert from unsigned char* to QString

    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.

Similar Threads

  1. unsigned char * to QString
    By elina.du in forum Qt Programming
    Replies: 2
    Last Post: 25th March 2009, 08:33
  2. convert unsigned char * to QString
    By sepehr in forum Qt Programming
    Replies: 4
    Last Post: 9th December 2008, 20:31
  3. How to convert QString to char *
    By rajeshs in forum Qt Programming
    Replies: 7
    Last Post: 27th September 2007, 10:32
  4. QString to unsigned char *
    By darksaga in forum Qt Programming
    Replies: 9
    Last Post: 23rd July 2007, 07:52
  5. Converting QString to unsigned char
    By salston in forum Qt Programming
    Replies: 3
    Last Post: 24th April 2006, 22:10

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.