[Development] Weird offseting in QDataStream

Thiago Macieira thiago.macieira at intel.com
Fri Nov 8 22:41:06 CET 2013


On sexta-feira, 8 de novembro de 2013 10:34:00, Andreas Aardal Hanssen wrote:
> 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.

We could provide an iomanipulator like QTextStream and iostream:

	ds << qSetSinglePrecision << f << qSetDoublePrecision << d;

	ds >> qSetSinglePrecision >> f >> qSetDoublePrecision >> d;

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.qt-project.org/pipermail/development/attachments/20131108/4aa4bf22/attachment.sig>


More information about the Development mailing list