struct my_struct{ int a; int b;};
QMap<QString, my_struct> mapMain;
QByteArray arr; QDataStream stream(&arr, QIODevice::WriteOnly); stream.setVersion(QDataStream::Qt_4_7); my_struct udt; udt.a = 1; udt.b = 2; mapMain.insert("Hello", udt); stream << mapMain;
C:\dev\est_strucrt-build-desktop\..\..\Qt\2010.05\qt\src\corelib\io\qdatastream.h:427: ошибка: no match for 'operator<<' in 'operator<<(((QDataStream&)((QDataStream*)out)), ((const QString&)((const QString*)it.QMap<Key, T>::const_iterator::key [with Key = QString, T = my_struct]()))) << it.QMap<Key, T>::const_iterator::value [with Key = QString, T = my_struct]()'
friend QDataStream &operator<<(QDataStream &out, const QMap<QString, my_struct> &map) { //Тут код :) return out; }
friend QDataStream &operator<<(QDataStream &out, const QMap<QString, my_struct> &map) { QMapIterator<QString, my_struct> iter(map); while(iter.hasNext()) { iter.next(); out << iter.key(); out << iter.value().a; out << iter.value().b; } return out; }
template <class Key, class T>Q_OUTOFLINE_TEMPLATE QDataStream &operator<<(QDataStream &out, const QMap<Key, T> &map){ out << quint32(map.size()); typename QMap<Key, T>::ConstIterator it = map.end(); typename QMap<Key, T>::ConstIterator begin = map.begin(); while (it != begin) { --it; out << it.key() << it.value(); } return out;}
C++ (Qt)QDataStream &operator<<(QDataStream &out, const my_struct &struct){ out << struct.a; out << struct.b; return out;}
QByteArray arr;QDataStream stream(&arr, QIODevice::WriteOnly);stream.setVersion(QDataStream::Qt_4_7);QMapIterator<QString, my_struct> iter(mapMain); while(iter.hasNext()) { iter.next(); stream << iter.key(); stream << iter.value(); }
C++ (Qt)typename QMap<Key, T>::ConstIterator it = map.end();