Re: QDataStream>>(int) skipping one byte?
QDataStream reads and writes in encoded format, which includes the QDataStream version to ensure compatibility when reading/writing the data. Since your data was not written using QDataStream, your issue is likely due to the format of data written using fwrite doesn't contain the exact format expected by QDataStream.
The x'0D' following your string is likely a carriage return. From the docs:
To take one example, a char * string is written as a 32-bit integer equal to the length of the string including the '\0' byte, followed by all the characters of the string including the '\0' byte. When reading a char * string, 4 bytes are read to create the 32-bit length value, then that many characters for the char * string including the '\0' terminator are read.
So when you write your file using fwrite, does the 32-bit integer length include the carriage return and trailing '\0' byte in its length?
Edit: QDataSteam also encodes a version number into the stream, which could also be where you're getting tripped up since your file wasn't written with QDataStream.
I write the best type of code possible, code that I want to write, not code that someone tells me to write!
Bookmarks