What does the '*' and ')' mean in the output of qDebug()<<QByteArray?

70 Views Asked by At

Code:

QByteArray receive=serialport.readAll();
qDebug()<<"receive="<<receive;

qDebug output:

receive= "\x02\x03*\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x9D)"

What does the * and ) mean?

2

There are 2 best solutions below

0
Jackoo On

'*' is \x2a and ')' is \x29.

I guess the qDebug()<<QByteArray prints a byte as a ASCII symbol if it's printable, and prints its value if not.

0
phuclv On

From the documentation:

Writes the byte array, t, to the stream and returns a reference to the stream. Normally, QDebug prints the array inside quotes and transforms control or non-US-ASCII characters to their C escape sequences (\xAB). This way, the output is always 7-bit clean and the string can be copied from the output and pasted back into C++ sources, if necessary.

To print non-printable characters without transformation, enable the noquote() functionality. Note that some QDebug backends might not be 8-bit clean.

QDebug Class - QDebug &QDebug::operator<<(const QByteArray &t)

So printable ASCII characters will be printed as characters, other byte values will be escaped