Question

I have a QByteArray i create manually:

QByteArray hexArray(QByteArray::fromHex("495676"));

If this was encoded ASCII it would be "IVv". If I want to get a single byte of data from that array. I can do that like this:

qDebug() << messageToBeSent_raw[0];

However, that outputs I, which is correct but I would like to get 49. What I'm looking for is an equivalent of the QByteArray::toHex() just for a single byte. Is there a way to do it?

Was it helpful?

Solution

You can use QString::number.

qDebug() << QString::number(hexArray[0], 16);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top