[Development] Weird offseting in QDataStream
Olivier Goffart
olivier at woboq.com
Fri Nov 8 10:57:54 CET 2013
On Friday 08 November 2013 10:42:16 Yves Bailly wrote:
> I can understand this for high-level Qt objects, but what about lower-level
> data? Does this mean I can't use QDataStream to read a file written by
> some other program, and/or can't use it to *write* a file which could be
> read back by some other program? Again, only using low-level data, ints,
> floats, and so on.
>
> If that is true, then it's a huge step backward in the ease of use provided
> by Qt in the realm of reading/writing binary files.
>
> Just to give a context, the goal here is to read and write binary
> STL (stereolithography) or PLY files. I have old Qt3 code which works like a
> charm, reading and writing files usable to and from other soft (e.g.
> Blender). Now moving that old code to Qt5 it seems to not work as expected,
> despite using only basic, low-level data types.
You can use
stream.setVersion(QDataStream::Qt_3_3);
To get back to the Qt3 behaviour.
Else, yes, you will have to change the floating point precision before every
call. It was changed in Qt 4.6 for compatibility with qreal that can be
float or double depending on the platform.
Perhaps one could add a QDataStream::FloatingPointPrecision::AutoPrecision,
that would not be a bad idea.
--
Olivier
Woboq - Qt services and support - http://woboq.com - http://code.woboq.org
More information about the Development
mailing list