[Qt-interest] how to output a user defined struct data to datastream?

Vincent Cai wcai at cypress.com
Thu Oct 13 10:49:27 CEST 2011


Sorry, but I think the endian is controlled by QDataStream which is platform independent, am I wrong?

-----Original Message-----
From: Andre Haupt [mailto:andre at bitwigglers.org]
Sent: 2011年10月13日 16:46
To: Vincent Cai
Cc: Samuel Gaist; Qt-interest
Subject: Re: [Qt-interest] how to output a user defined struct data to datastream?

On Thu, Oct 13, 2011 at 01:21:31AM -0400, Vincent Cai wrote:
> Thanks.
>         I have try below code and it can work properly, but the code seems a little weird, is there any better way to write the code?
>
>         for (int i = 0; i < sizeof(headerInfo); ++i)
>     {
>         out << (quint8)(*(reinterpret_cast<const char *>(&headerInfo)+i));
>     }

That does not work cross platform, depending on the endianess of the
target system. Please read Samuels answer.

Cheers,

Andre

This message and any attachments may contain Cypress (or its subsidiaries) confidential information. If it has been received in error, please advise the sender and immediately delete this message.


More information about the Qt-interest-old mailing list