[Development] Weird offseting in QDataStream

Yves Bailly yves.bailly at sescoi.fr
Fri Nov 8 10:01:45 CET 2013


Greetings all,

Here's some weird behaviour when using QDataStream.
Using Qt 5.2.0 beta 
qt-windows-opensource-5.2.0-beta1-msvc2012_opengl-x86_64-offline_2013-10-24_17-14-50-112.exe
on Windows 7 64bits, MSVC 2012

I try to read a float from a file, displaying the file position.
Here's the code:
   QFile f("my_file");
   if ( ! f.open(QIODevice::ReadOnly) )
   {
     return -1;
   }
   QDataStream ds(&f);
   ds.setByteOrder(QDataStream::LittleEndian);
   qDebug() << f.pos();
   float flt;
   ds >> flt;
   qDebug() << f.pos();

As a float is 4 bytes, I would expect the second f.pos() to display "4"... but
it displays "8", as if QDataStream had moved 8 bytes ahead instead of just 4.
Needless to say, the read float is wrong...

Am I missing something here, or is it a bug?

Any hint appreciated.

-- 
      /- Yves Bailly - Software developer   -\
      \- Sescoi R&D  - http://www.sescoi.fr -/
"The possible is done. The impossible is being done. For miracles,
thanks to allow a little delay."



More information about the Development mailing list