QDataStream
encodes into a special Qt format, it doesn't format into 'raw' binary.
You will need to serialise the data yourself. I would recommend just appending into the QByteArray
. For example to serialize an uint16_t
in network byte order you could use a function like this:
void appendUint16NBO(QByteArray& ba, uint16_t i)
{
ba.append(char((i >> 8) & 0xFF));
ba.append(char(i & 0xFF));
}
You would use the function as follows:
QByteArray datagram;
appendUint16NBO(datagram, 0x0000);
appendUint16NBO(datagram, 0x8400);
The QByteArray
would then contain: 00 00 84 00
.