• 6124阅读
  • 2回复

[提问]QMultiMap insert 求助 [复制链接]

上一主题 下一主题
离线saga_uni
 
只看楼主 倒序阅读 楼主  发表于: 2011-03-30
请大家帮忙看一下,我的insert 为什么会出错。。。

#include<QApplication>
#include <QMultiMap>
#include<QVector>
int main(int argc, char *argv[])
{
     QApplication app(argc, argv);
     QMultiMap<QVector<char>,QVector<ushort> > multi_map;
  QVector<char> key;
  key.push_back('a');
  key.push_back('b');
  QVector<ushort> val;
  val.push_back(100);
  multi_map.insert(key,val);
     return app.exec();
}

编译错误如下:
test.cpp:13:   instantiated from here
/usr/include/QtCore/qmap.h:100: 错误:no match 为‘operator<’在‘key1 < key2’中
/usr/include/QtCore/qchar.h:381: 附注:备选为: bool operator<(QChar, QChar)
/usr/include/QtCore/qbytearray.h:500: 附注:         bool operator<(const QByteArray&, const QByteArray&)
/usr/include/QtCore/qbytearray.h:502: 附注:         bool operator<(const QByteArray&, const char*)
/usr/include/QtCore/qbytearray.h:504: 附注:         bool operator<(const char*, const QByteArray&)
/usr/include/QtCore/qstring.h:883: 附注:         bool operator<(const char*, const QString&)
/usr/include/QtCore/qstring.h:896: 附注:         bool operator<(const char*, const QLatin1String&)
/usr/include/QtCore/qstring.h:909: 附注:         bool operator<(const QLatin1String&, const QLatin1String&)
/usr/include/QtCore/qstring.h:1119: 附注:         bool operator<(const QStringRef&, const QStringRef&)
make: *** [test.o] 错误 1

离线saga_uni
只看该作者 1楼 发表于: 2011-03-30
回 楼主(saga_uni) 的帖子
自己解答:
map 插入时要根据键值进行排序,QVector内部没有定义比较大小的operator <
,故我换成了QString
离线leos
只看该作者 2楼 发表于: 2011-07-05
不完全正确 ……
The rain falls because the sky can no longer handle its weight. Just like the tears fall because the heart can no longer handle the pain.
快速回复
限100 字节
 
上一个 下一个