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?

Était-ce utile?

La solution

You can use QString::number.

qDebug() << QString::number(hexArray[0], 16);
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top