[Development] Weird offseting in QDataStream

Olivier Goffart olivier at woboq.com
Fri Nov 8 11:10:25 CET 2013

On Friday 08 November 2013 11:03:40 André Somers wrote:
> Olivier Goffart schreef op 8-11-2013 10:57:
> > 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.
> What would that mode do, exactly? Isn't the whole point that qreal may
> be defined as float or double, and thus you don't know how it will be
> stored in QDataStream? You cannot detect which meaning of qreal was used
> when the file was written... Or do you mean that it should be something
> like MixedPrecision or TypePrecision that would always use 4 bytes for
> float and 8 for double again (and wreck havoc if you try to use qReal
> for reading or writing)? That indeed would be good, I think. I think
> it's a bit weird that in order to support streaming qreal, you basicaly
> stop supporting reading and writing floats or doubles.

Yes, what I called AutoPrecision would be 8 bytes when passed a double, and 4 
bytes when passed float. 

It would be a bad idea to use that mode with qreal typedef which can vary on 
the platform.  (But qreal defaults to double on all the platform from Qt 5.2)


Woboq - Qt services and support - http://woboq.com - http://code.woboq.org

More information about the Development mailing list