[Development] Weird offseting in QDataStream
Andreas Aardal Hanssen
andreas at hanssen.name
Fri Nov 8 10:34:00 CET 2013
On 08 Nov 2013, at 10:15, Yves Bailly <yves.bailly at sescoi.fr> wrote:
> Le 08/11/2013 10:05, Giuseppe D'Angelo a écrit :
>> See QDataStream::setFloatingPointPrecision. The default is double.
> That's pretty strange... what if I want to read a float then a double? do I
> have to switch between the two each time?
> Does this means it's impossible to use code like this:
> float f;
> double d;
> datastream >> f >> d;
QDataStream stores your content in a portable binary format. Specifying the floating point precision makes it clear that real numbers, be them represented in floats or doubles in C++, are stored as floats or doubles in file.
If you want to store a float as a float, and then a double as a double, you need to change the precision of QDataStream in between calls. Plus, the code that reads the file must match the code that wrote the stream.
More information about the Development