Reputation: 19203
I've tried the following:
qDebug() << QByteArray("\x00\x10\x00\x00").size();
and i get 0 instead of 4 witch i would espect.
What would be a good data type to hold this 4 bytes of data as i need to later write them to a socket so they must remain exactly like you see them above?
Upvotes: 1
Views: 1324
Reputation: 5393
The constructor QByteArray(const char* str)
uses qstrlen
on the argument. Since your string starts with a 0x00 byte, qstrlen
returns 0, thus the resulting QByteArray is 0 bytes long.
To avoid the qstrlen
check, use the QByteArray(const char* str, int size)
constructor:
qDebug() << QByteArray("\x00\x10\x00\x00", 4).size();
will print 4 as you expect.
Upvotes: 4