io - Writing single bytes to a QDataStream -
i want write series of bytes qdatastream. when viewed in hex editor, i'd resulting file this:
0x dead my attempt looks this:
qfile file("test.txt"); file.open(qiodevice::writeonly); qdatastream stream(&file); stream << ((char)0xde); stream << ((char)0xad); file.close(); when open test.txt hex editor, can see instead of writing these single bytes, datastream has left-padded them full words, , file looks this:
0x ffff ffde ffff ffad what's right way this?
the qiodevice left-shift operator (<<) doesn't have overloaded definition char primitive, cast int.
it have definition qint8 type. changing code fixes output:
stream << ((qint8) 0xde); stream << ((qint8) 0xad);
Comments
Post a Comment