QDatastream
-
On Linux(64bit g++), I have :
@
typedef struct
{
qint64 x,y;
bool break_flag;
} PNT;
@
and on Vista(mingwc++32) I have
@
typedef struct
{
quint32 x,y;
bool break_flag;
} PNT;
@
Will the serialized data using QDatastream be protable between Linix and Window?Thanks.
[Edit] Code wrappers added; koahnig
-
Qt is binary compatible across platforms but you still have to use the same data types, and in your particular case you have 8 vs 4 byte integers. Why do you have different types to begin with? I could see an issue if you use plain integers which vary with the architecture "width" they were built for but in your case you explicitly define different data types, not the compiler.
Since you are not using those to hold architecture width specific data but coordinates, you can conform either one of the solutions to gain compatibility, for example using 32 bit integers in both cases, since the 32 bit build will have a harder time working with 64 bit integers and you hardly need that much precision.
-
Please remember next time to use "code wrappers ":http://developer.qt.nokia.com/wiki/ForumHelp#e3f82045ad0f480d3fb9e0ac2d58fb01
-
There is a reason(not a good one) for this. When I started to write this program, I wasn't thinking about
protable across all platforms. I started on Vista and used integer instead of qint32. So, a lots of calculations and manipulation are using int(4 bytes). the program and data are portable between Linux(32 bits) and Vista. Therefore I have no choice but to declare all integer to either qint32 or qint64.
Which one of the two(qint32 or qin64) will most likely give me less problem? -
The very reason Qt uses all those typedefs is to provide portability, because if you use plain ints the size is determined by the compiler.
Just use qint32 in both cases, qint64 won't give you problems but will give you lower performance in 32bit builds and larger memory footprint. I really doubt you need 20 digit precision :)
-
I almost forget one thing. Sometime, I use QPoint to exchange with my PNT struct like spnt.x=qpnt.x();
It will work if qpnt.x>=0, but it won't work if it is negative. Oh well. I just used integer in my struct and then convert it to qint32 before serialize it. And do the other way around after desrialization.Thanks.