Results 1 to 9 of 9

Thread: Problems converting raw data to struct when using QDataStream

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Problems converting raw data to struct when using QDataStream

    You seem to be understanding that serializing with QDataStream is a non-trivial operation, but at the same time you expect deserialization to be done by bit-for-bit reinterpretation. This is dangerously wrong. If you use QDataStream to serialize, you must use QDataStream to deserialize.

    You seem to be understanding that serializing with QDataStream is a non-trivial operation, but at the same time you expect deserialization to be done by bit-for-bit reinterpretation. This is dangerously wrong. If you use QDataStream to serialize, you must use QDataStream to deserialize.


    Added after 5 minutes:


    By the way, your code should not depend on the precise layout of the serialized data. Just let QDataStream encode and decode, or design your own format as I explained before. Also, do not use types such as "unsigned int" in your structure because the range of values of this type depends on the architecture. Use a fixed-size type such as uint32_t.
    Last edited by yeye_olive; 3rd July 2014 at 16:21.

  2. The following user says thank you to yeye_olive for this useful post:

    Momergil (3rd July 2014)

Similar Threads

  1. Problems with marshalling a struct to Qt/DBus
    By laumann in forum Qt Programming
    Replies: 3
    Last Post: 21st January 2014, 10:40
  2. Replies: 6
    Last Post: 24th November 2010, 18:59
  3. Problems with QDataStream
    By Doug Broadwell in forum Qt Programming
    Replies: 1
    Last Post: 6th August 2008, 22:02
  4. QDataStream class/struct & stream operators
    By darksaga in forum Qt Programming
    Replies: 1
    Last Post: 1st August 2008, 19:40
  5. sharing struct data throughout program
    By vonCZ in forum Newbie
    Replies: 3
    Last Post: 9th July 2007, 17:21

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.