Convert QByteArray include special content to QString , diaplay is not normal



  • Hi, Merry Christmas.

    I had one QByteArray and there has some special content, like '0xa3 0xa8 0xce ...'. they are display is normal in QByteArray, but, when i convert QByteArray to QString. And the special content display is not normal.

    About this question, How to display normal in QString?

    Thank u.

    ba    "225887b89c239#75*£¨7*4*ÎÞ×ù*2010*ÎÞ*80*E7E63F10"    QByteArray
    
        '2'     50        0x32    char
        '2'     50        0x32    char
        '5'     53        0x35    char
        '8'     56        0x38    char
        '8'     56        0x38    char
        '7'     55        0x37    char
        'b'     98        0x62    char
        '8'     56        0x38    char
        '9'     57        0x39    char
        'c'     99        0x63    char
        '2'     50        0x32    char
        '3'     51        0x33    char
        '9'     57        0x39    char
        '#'     35        0x23    char
        '7'     55        0x37    char
        '5'     53        0x35    char
        '*'     42        0x2a    char
        'ᆪ'     -93/163    0xa3    char
        'ᄄ'     -88/168    0xa8    char
        '7'     55        0x37    char
        '*'     42        0x2a    char
        '4'     52        0x34    char
        '*'     42        0x2a    char
        'ᅫ'     -50/206    0xce    char
                -34/222    0xde    char
        'ᅲ'     -41/215    0xd7    char
                -7/249    0xf9    char
        '*'     42        0x2a    char
        '2'     50        0x32    char
        '0'     48        0x30    char
        '1'     49        0x31    char
        '0'     48        0x30    char
        '*'     42        0x2a    char
        'ᅫ'     -50/206    0xce    char
                -34/222    0xde    char
        '*'     42        0x2a    char
        '8'     56        0x38    char
        '0'     48        0x30    char
        '*'     42        0x2a    char
        'E'     69        0x45    char
        '7'     55        0x37    char
        'E'     69        0x45    char
        '6'     54        0x36    char
        '3'     51        0x33    char
        'F'     70        0x46    char
        '1'     49        0x31    char
        '0'     48        0x30    char
    
    qsBarData    "225887b89c239#75*��7*4*����*2010*��*80*E7E63F10"    QString
    


  • Hi, you have to tell QString which encoding you are using, like

    	QByteArray ba="blabla";
    	ba[2]=163;
    	ba[3]=168;
    	QString textLat1=QString::fromLatin1(ba);
    	QString textUTF8=QString::fromUtf8(ba);
    	qDebug()<<"Latin1 enconding "<<textLat1<<" utf8 encoding " << textUTF8;
    
    

    produces

    Latin1 enconding  "bl£¨la"  utf8 encoding  "bl��la"
    

    Only QString knows of an encoding, ByteArray is - as the name sugests - a dumb array of bytes with no character meaning.



  • @stryga42 OK, Thank u, i will try it again. Thanks and regards.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.