Results 1 to 7 of 7

Thread: QDataStream>>(int) skipping one byte?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2015
    Posts
    36
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default QDataStream>>(int) skipping one byte?

    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:
    1. //dataset description
    2. fileStream>>(int)tempInt; //length of description, this is correctly loaded, int = 121
    3. fileStream.readRawData(charBuffer,tempInt); // this is correctly loaded too
    4.  
    5. qDebug() << "Dataset descr length: " << tempInt;
    6.  
    7. for (int i=0; i<tempInt; i++){
    8. dataSetDescription += charBuffer[i]; // it works too
    9. }
    10.  
    11. //signals count
    12. fileStream>>(int)signalsCount; //and it doesn't work there, it should read int=13, yet it reads 16777216
    To 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?
    Attached Images Attached Images
    Last edited by Khaine; 15th March 2016 at 20:20.

Similar Threads

  1. byte to uint
    By #Dragon in forum Qt Programming
    Replies: 2
    Last Post: 27th October 2015, 16:29
  2. QDataStream on enum (byte length)
    By StarShaper in forum Qt Programming
    Replies: 0
    Last Post: 2nd February 2012, 01:28
  3. Replies: 3
    Last Post: 19th April 2010, 14:16
  4. Phonon skipping two tracks
    By matio in forum Qt Programming
    Replies: 4
    Last Post: 24th November 2009, 17:03
  5. Byte shifting in C
    By tntcoda in forum General Programming
    Replies: 3
    Last Post: 14th November 2008, 22:40

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.