Results 1 to 6 of 6

Thread: Problem with QDataStream operators

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,330
    Thanks
    317
    Thanked 871 Times in 858 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Problem with QDataStream operators

    maybe you should provide an explicit template specialization for this to work.
    Well, maybe, but the QMap<> base class for my CClassColorMap class is fully specialized. My QDataStream operators use my derived class, not QMap<>. Even if I provided a set of QDataStream operators for a fully specialized QMap<>, that still is not the same as the operators for my own class. If I had additional data members in my class that I wanted to serialize, operators for a fully specialized QMap<> wouldn't know about them.

    I think this is a defect in the lookup system for the QDataStream operators used in QMetaType. I haven't tried this with classes derived from other Qt base classes (like QString, f.e.) but my hunch is the same thing would happen. I'm under deadline pressure and unfortunately don't have the time to investigate.

    Edit: OK, I threw my deadline out the window and tested this using a class derived from QString. Everything I said above is completely wrong. At first, I thought that my string class QDataStream operators were not being called, so I changed the derived class to be a top level class with a QString member. The operators still weren't called. Huh?

    Then I realized that on import if QSettings doesn't find a value with the key you are asking for, it doesn't call operator>>() because there is nothing to serialize. When I exited the program (and saved the QSettings back out to the file), the operator<<() was called. I changed my string class back to being derived from QString, and sure enough, it works now on import too, because now there's a key in the QSettings file.

    I did the same for my QMap<> class - turned it back into a derived class of QMap<>, and it works now too. To make sure, I manually deleted all of the relevant entries from the QSettings file. On import, the operator>>() is not called, but on export operator<<() is called as it is supposed to be.

    My bad. Jumped to a wrong conclusion and because I was doing everything in the debugger and exiting before the export to the QSettings file occurred, I assumed a defect.

    I apologize for wasting everyone's time chasing a wrong conclusion.
    Last edited by d_stranz; 4th September 2014 at 22:12.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problem with QDataStream operators

    At least we all learned something.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    d_stranz (5th September 2014)

Similar Threads

  1. Regular Expression for Operators
    By parulkalra14 in forum Qt Programming
    Replies: 6
    Last Post: 7th January 2014, 10:36
  2. Define a QRegExp containing arithmetic operators
    By aaditya190 in forum Newbie
    Replies: 1
    Last Post: 4th December 2013, 11:38
  3. Store QVector to QDataStream problem
    By ruben.rodrigues in forum Newbie
    Replies: 1
    Last Post: 2nd August 2010, 09:27
  4. QDataStream class/struct & stream operators
    By darksaga in forum Qt Programming
    Replies: 1
    Last Post: 1st August 2008, 19:40
  5. Problem with QTcpSocket and QDataStream
    By Valheru in forum Qt Programming
    Replies: 4
    Last Post: 16th September 2006, 13:08

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.