PDA

View Full Version : Index of two Hexvalues in QByteArray



dj boris
10th March 2011, 20:21
Hello,

How can I pick the index of two (following) Hexvalues in a QByteArray?

Example:
I have a QByteArray with the following Hexvalues: "ff d8 12 89 65 ff"
When I wish the index of "d8 12", it must return: 1 or 2.
With the index, I can use .mid to make a Substring.

Are there any ways to do it?

Thanks
-Boris

ChrisW67
10th March 2011, 22:45
QByteArray::indexOf()

dj boris
11th March 2011, 23:38
Hello,
Yes, I know the function of ::indexOf(), but I don't know how to put 2 following hex values into a QByteArray.
Have the ::fromHex() Function a good performance?

-Boris

ChrisW67
12th March 2011, 00:28
I don't understand. Your initial problem statement said you already have these 6 bytes in a QByteArray. You use indexOf() to find the two byte sequence you are looking for and then QByteArray::mid() to create another QByteArray containing a copy of the two bytes. Seems rather pointless given that you know what the resulting QByteArray will contain before you even start.