Hi,
I'm pretty new to qt (and c++ in general), so maybe this is not a qt specific "problem".
I have a binary file that I open and I read a few bytes. After that I read a few more bytes in a loop. After that, as far as I understood, file.pos() should be equal to all the bytes I have read so far, but for a few files, there is a mismatch.

code snippet:

Qt Code:
  1. char buffer[255];
  2. qint64 bytesRead;
  3. QFile file(fileName);
  4. if (!file.open(QIODevice::ReadOnly | QIODevice::Text)){
  5. qDebug() << "could not open" << fileName;
  6. return -1;
  7. }
  8. bytesRead = file.read(buffer, 16);
  9. if(bytesRead != 16){
  10. qDebug() << "mismatch bytes read" << bytesRead << " != " << 16;
  11. }
  12. if(file.pos() != 16){
  13. qDebug() << "mismatch" << file.pos() << " != " << 16;
  14. }
  15. ...
  16. for (int i = 0; i < 7; i++) {
  17. bytesRead = file.read(buffer, 24);
  18. ...
  19. if(bytesRead != 24){
  20. qDebug() << "mismatch bytes read" << bytesRead << " != " << 24;
  21. }
  22. if(file.pos() != (16 + (i+1)*24)){
  23. qDebug() << "mismatch" << file.pos() << " != " << (16 + (i+1)*24);
  24. }
  25. }
  26. file.close()
To copy to clipboard, switch view to plain text mode 

and the output is
Qt Code:
  1. mismatch 185 != 184
To copy to clipboard, switch view to plain text mode 

This happens not on all files, so I am wondering what I am doing wrong...
Any help or pointer is appreciated!