I have a problem with reading binary file. File was written using standard C++ fwrite functions, and now I want to read it using QDataStream. Yet I have problem that I cannot explain.
Qt Code:
//dataset description fileStream>>(int)tempInt; //length of description, this is correctly loaded, int = 121 fileStream.readRawData(charBuffer,tempInt); // this is correctly loaded too qDebug() << "Dataset descr length: " << tempInt; for (int i=0; i<tempInt; i++){ dataSetDescription += charBuffer[i]; // it works too } //signals count fileStream>>(int)signalsCount; //and it doesn't work there, it should read int=13, yet it reads 16777216To copy to clipboard, switch view to plain text mode
IT'S NOT ENDIANESS PROBLEM! One byte is simply skipped for whatever reason.
http://s11.postimg.org/tp2xi4hz5/hex.png
Take a look at this binary file. Whole name of dataset is loaded correctly and ended with . sign. After this . sign I want to read 4 bytes in little endian being number of signals. As you can see it should read 0D000000, which is 13. YET it totally skips 0D byte and proceeds further, and reads 00000010 which means 16777216 in little endian hex. I just have no clue what is happening here. You can see, that there is nothing in code that would order it to move this one byte further. Also same algorithm you see is used in reading many things before signals count and it skips no bytes, and all chars are converted to strings correctly. Any ideas?


Reply With Quote



Bookmarks