[Qt-interest] QByteArray::fromRawData() oddity...

Thiago Macieira thiago at kde.org
Wed Nov 18 01:16:11 CET 2009


Em Quarta-feira 18. Novembro 2009, às 00.39.24, BRM escreveu:
> Question:
> 
> Given the following structure:
> 
> struct exampleStructure
> {
>      quint32 command;
>         quint32 other;
>         quint32 picnic;
> 
>         void Pack()
>                 {
>                 command = htonl(command);
>                 other = htonl(other);
>                 picnic = htonl(picnic);
>                 }
>         void UnPack()
>                 {
>                 command = ntohl(command);
>                 other = ntohl(other);
>                 picnic = ntolh(picnic);
>              }
> };
> 
> Should the following bits of code produce the same result:
> 
> struct exampleStructure test;
> memset(&test,0,sizeof(struct exampleStructure);
> 
> // bit #1:
> QByteArray data = QByteArray::fromRawData((char*)&test,sizeof(struct
>  exampleStructure));
> 
> // bit #2:
> QByteArray data2((char*)&test,sizeof(struct exampleStructure));
> 
> I just spent most of the day figuring out an issue that tracked down to
>  that difference - where #2 worked while #1 did not. I would have thought
>  they'd produce the same result (e.g. data2 should be the same as data).

They're not exactly the same operation, but data == data2.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Senior Product Manager - Nokia, Qt Development Frameworks
      PGP/GPG: 0x6EF45358; fingerprint:
      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091118/83b7eff2/attachment.bin 


More information about the Qt-interest-old mailing list