Am 08.11.2013 10:42, schrieb André Somers:
Christian Ehrlicher schreef op 8-11-2013 10:29:
Am 08.11.2013 10:15, schrieb Yves Bailly:
Le 08/11/2013 10:05, Giuseppe D'Angelo a écrit :
On 8 November 2013 10:01, Yves Bailly<yves.bai...@sescoi.fr>  wrote:
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?
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;
?
setFloatingPointPrecision does only change the way the floating point
numbers are stored in the data stream, not what you read from it.
Also I think you're wrong in what you want to do. You can't read data
from a file which was not stored with QDataStream before! See
http://qt-project.org/doc/qt-5.0/qtcore/qdatastream.html#details
That sounds very unlikely. It would mean that you cannot use symetric code for reading and writing data:

//writing
float f(3.14159);
double d(2.71828);
datastream << f << d;

//reading, would not work according to Christian
float f;
double d;
datastream >> f >> d; //would not work according to you

//reading, according to Christian
float f;
double df, d;
datastream >> df >> d;
f = static_cast<float>(d);

I'm quite sure that you _can_ use the symetric (first) version.

You're correct - you understood me wrong. :)

Christian
_______________________________________________
Development mailing list
Development@qt-project.org
http://lists.qt-project.org/mailman/listinfo/development

Reply via email to