2

My goal is to convert an hexadecimal value which is contained in a QString to its ASCII value.

I have :

QString hexaValue = receiveText.left(14); // receive texte is another QString

My problem here, is that I have my hexadecimal value in a Qstring and not in a QByteArray, so all of the solutions that I found are not working, I try to call .data() or fromHex() , but this ain't working here, because I'm forced to used a QString and not a QByteArray

Should I convert my QString to a QByteArray, is there a simple solution ?

1 Answer 1

4

You can just use QString::toLatin1to convert hex string to QByteArray and to convert it back to QString use either QString::fromLocal8Bit for local encoding or QString::fromUtf8 if your hex encoded string are in UTF8.

QString hexaValue = receiveText.left(14); // received text is another QString
QString textValue = QString::fromLocal8Bit(QByteArray::fromHex(hexaValue.toLatin1()));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.