Results 1 to 2 of 2

Thread: Need help with serialization of QMaps

  1. #1
    Join Date
    Jul 2006
    Posts
    2
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Need help with serialization of QMaps

    Hi,

    I try to serialize the member variable QMap <int, QByteArray> in an overloaded operator function, but I get the following compiler errror: no match for 'operator<<' in 'ds << map'

    This is my overloaded operator function
    Qt Code:
    1. QDataStream& operator<<(QDataStream& ds, const NetShmMessage & msg )
    2. {
    3. QMap<int, QByteArray> map;
    4. map[1] = QByteArray("one");
    5. map[2] = QByteArray("two");
    6.  
    7. ds << map;
    8. return ds;
    9. }
    To copy to clipboard, switch view to plain text mode 
    In my main I'm calling

    Qt Code:
    1. QBuffer tempDevice;
    2. tempDevice.open(QIODevice::WriteOnly);
    3. QDataStream stream(&tempDevice);
    4. stream << msgNet;
    To copy to clipboard, switch view to plain text mode 
    msgNet is an instance of NetShmMessage wich is holding the map.
    If I'm calling stream << map (with previos data definitions) in the main it is working, but not from the overloaded operator. What am I missing?

    The overloaded operator is defined as global with friend prefix.

    Any help would be really appreciated.
    Last edited by jpn; 5th May 2009 at 17:14. Reason: missing [code] tags

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Need help with serialization of QMaps

    Do you have appropriate includes? QMap, QDataStream..
    J-P Nurmi

Similar Threads

  1. serialization & data integrity
    By darksaga in forum Qt Programming
    Replies: 2
    Last Post: 28th August 2007, 13:04
  2. Serialization
    By donmorr in forum Qt Programming
    Replies: 4
    Last Post: 16th November 2006, 13:51

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.