Results 1 to 2 of 2

Thread: Object serialization with QDataStream

  1. #1
    Join Date
    Jan 2013
    Posts
    3
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Object serialization with QDataStream

    Hello,

    I am trying to overload operators << and >> for QDataStream and my class. I checked some tutorials and have been trying to use them for my issue and got it almost right. When I write to a file I believe it works properly as I checked a file with binary editor. It surely saves QStrings properly. I can't tell anything about QDate and QTime variables as they don't appear in understandable way in Hex Fiend. Also I am aware that constructor is not used properly as when it isn't commented out it makes my app crash. So any hints to make it proper would be greatly appreciated.

    Qt Code:
    1. QDataStream &operator>>(QDataStream &in, Task &task) {
    2.  
    3. bool isDone;
    4. QString name;
    5. QString description;
    6. QDate dayClicked;
    7. QTime start;
    8. QTime end;
    9. bool neededReminder;
    10. QDateTime reminderTime;
    11. quint32 time;
    12.  
    13. in >> name >> description >> dayClicked >> start >> end >> reminderTime >> isDone >> neededReminder >> time;
    14.  
    15. qDebug() << name << description << dayClicked.toString() << start.toString() << end.toString()
    16. << reminderTime.toString() << isDone << neededReminder << time;
    17.  
    18. task = Task(isDone, name, description, dayClicked, start, end, (int)time, neededReminder);
    19. return in;
    20. }
    To copy to clipboard, switch view to plain text mode 


    What qDebug is returning: "" "" "" "00:00:00" "00:00:00" "" false false 0
    Last edited by jahsiotr; 20th January 2013 at 13:18.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Object serialization with QDataStream

    Also I am aware that constructor is not used properly as when it isn't commented out it makes my app crash. So any hints to make it proper would be greatly appreciated.
    Constructor of what?

    What qDebug is returning: "" "" "" "00:00:00" "00:00:00" "" false false 0
    Is this incorrect? How are you creating the stream you are reading from? Are you reading the data from where you think you are reading from? Are the fields written to the stream in the same order you are reading them?

Similar Threads

  1. Replies: 0
    Last Post: 10th December 2011, 11:17
  2. QDataStream and QSql Object. Urgent!! please
    By ruben.rodrigues in forum Qt Programming
    Replies: 2
    Last Post: 15th August 2011, 23:57
  3. QDataStream and serialization
    By pdoria in forum Qt Programming
    Replies: 5
    Last Post: 11th November 2009, 09:42
  4. QDataStream-serialization not writting to file
    By john_god in forum Qt Programming
    Replies: 4
    Last Post: 1st August 2009, 12:27
  5. [Qt4] qdatastream/qstring serialization
    By fabo in forum Qt Programming
    Replies: 4
    Last Post: 19th April 2006, 18:31

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.