PDA

View Full Version : Compatibility of QDataStream btw. 32 and 64bit



olidem
7th January 2012, 18:54
I have written an application using Qt 4.5.2 a few years ago.

Now I wanted to port that code to the latest version of Qt (4.7.4),
and did not think further about the fact that I am now using a 64 bit OS (Mac OS X Lion).

Now I ran into trouble with my serialization routines which all rely on QDataStream.

The problem is that I did not use the qreal, qint32, qint64.... types in my sources,
and just declared int's and float's.

Is it enough to use the QDataStream::setVersion(Qt::Qt_4_5)?
Is Qt aware of serializing an int under 32bit in the same way as under 64bit?

Thanks for your help in advance!
olidem

wysota
7th January 2012, 19:16
Note, there are no operators for serializing "int", only qint32, qint64, etc. So your ints are in fact treated as they had a defined length (e.g. int is equal to qint32 on 32bit machines). Thus if you store an int on 32 bit machine, you will store it as qint32, so you have to read it back as qint32. Setting the version of Qt will not change anything.

olidem
7th January 2012, 19:28
So, this means that you're lost in case you used standard int's and float's ...?

On the other hand, if we assume char's are 1 byte in every architecture,
then


QVector<char> vec;
vec << 'a' << 'b';
QDataStream d;
d << vec;

then the latter code would be 'protable' and do the same on every architecure?
(I have the length of the vector in mind...it will be transmitted in an unambiguous way, right?)