Z
Z
Zakhar Alekseenko2014-04-08 08:19:24
Qt
Zakhar Alekseenko, 2014-04-08 08:19:24

How to convert string like 0x0102 0x304f to QByteArray?

Hello.
We have a QString like "0x0102 0x304f" and so on, it needs to be converted to a QByteArray. So that it
contains qarr[0] = 0x01
qarr[0] = 0x02
qarr[0] = 0x30
qarr[0] = 0x4f

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
tugo, 2014-04-08
@tugo

QString str = "0x0102 0x304f";
str.remove("0x");
str.remove(" ");
QByteArray arr = str.toLatin1();
QByteArray qarr = QByteArray::fromHex(arr);

D
DancingOnWater, 2014-04-08
@DancingOnWater

What do you need a dock for?

QString str;
QByteArray array;
array.append(str);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question