Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Convert QByteArray include special content to QString , diaplay is not normal
Forum Update on Monday, May 27th 2025

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

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 507 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • joeQJ Offline
    joeQJ Offline
    joeQ
    wrote on last edited by
    #1

    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
    

    Just do it!

    1 Reply Last reply
    0
    • S Offline
      S Offline
      stryga42
      wrote on last edited by stryga42
      #2

      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.

      joeQJ 1 Reply Last reply
      3
      • S stryga42

        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.

        joeQJ Offline
        joeQJ Offline
        joeQ
        wrote on last edited by
        #3

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

        Just do it!

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved