简体   繁体   中英

QByteArray filled with \x…\x… to QString

I'm receiving serial data trough a QByteArray in the following way

QByteArray serialdata = testport->readAll();
qDebug() << serialdata;

qDebug spills out things like

...\\x00T\\xAAN\\x82v\\xA9k\\x7F\\xEE\\xCEMf\\x1C\\xAA...

I know there are Strings/Chars behind this, but have absolute no clue what format is used. I've searched Bing and this board but found no clue. What confuses my even more is, that those pieces have a different length. Some are \\x12, some are \\x123 or even \\x1234.

Can anyone tell me what Codec or format that is and how I transform that into a QString?

qDebug formats the array so that it can be safely displayed, ie turns the display format into the format of a C string literal, where non-ASCII-printable characters are escaped and represented as hex octets.

Namely, \\xab means a byte with a value of a*16+b , where a and b are hexadecimal digits.

\\x1234 means {0x12, '3', '4'} .

\\x00T\\xAAN\\x82v\\xA9k\\x7F\\xEE\\xCEMf\\x1C\\xAA means {0x00, 'T', 0xAA, 'N', 0x82, 'v', 0xA9, 'k', 0x7F, 0xEE, 0xCE, 'M', 'f', 0x1C, 0xAA} . This is a "string" but definitely not a string in any natural human language, or at least not in any of the common encodings.

It's most definitely not an ASCII string. Looks more like line noise. Most likely you have not set the communication settings on the port to match those of the device you communicate with.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM