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

Andre Haupt andre at bitwigglers.org
Thu Oct 13 10:46:01 CEST 2011


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



More information about the Qt-interest-old mailing list