[Solved]help serializing a QMultiHash

  • i get this error:
    /usr/QtSDK/Desktop/Qt/473/gcc/include/QtCore/qdatastream.h:362: error: no match for ‘operator>>’ in ‘operator>>((* & in), (* & k)) >> t’

    I am trying to serialize a QMultiHash<QString,IndexItem> using QDataStream.. i have already defined operator << and >> for IndexItem like this:
    QDataStream & operator<<(QDataStream & stream,const IndexItem & item);
    QDataStream & operator>>(QDataStream & in,IndexItem & item);

    wherein i have serialized the contents of IndexItem...

    I get the error when i do
    stream >> index
    stream << index
    where stream is a QDataStream and index is the QMultiHash

    I get a similar error
    /usr/QtSDK/Desktop/Qt/473/gcc/include/QtCore/qdatastream.h:381: error: no match for ‘operator<<’ in ‘operator<<((* & out), (* & it.QHash<Key, T>::const_iterator::key with Key = QString, T = IndexItem)) << it.QHash<Key, T>::const_iterator::value with Key = QString, T = IndexItem

  • Do you get the same error if you try to stream an IndexItem directly?

  • Can you also specify the declaration of your QMultiHash?

  • Where did you define the operators? They should not be part of the IndexItem class, but be declared in the header of your IndexItem class. Also, make sure the the operators' header file is included if you declare them elswhere.

  • Volker: They are declared in the header outside the class.

    It is declared inside a class called Engine as a private member
    QMultiHash<QString,IndexItem> index;

    Haven't tried that... Will try that and tell you...

  • Thanks all.. i wasnt including the correct header.. I had a copy (for backup) which did not contain the stream operators.. and my program was including that one instead of the one I was editing... ;)

  • Doh!
    I guess we have all been in similar situations. I certainly have!

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.