insert()不适用于QMap变量

时间:2019-10-29 10:58:04

标签: c++ qt qmap

在我的课堂上,我有一个属性

QMap<QString, QMap<QString, QString>> a;

在类的方法中,我这样做:

QString s;
QMap<QString, QString> m;
QMap<QString, QMap<QString, QString>> m2;
m.insert(s, s);
m2.insert(s,m);

a.insert(s,m);

问题:“ m2”上的插入起作用,而“ a”上的插入给我一个编译错误。

为什么? m2和a属于同一类型。


编译错误:

error: passing ‘const QMap<QString, QMap<QString, QString> >’ as ‘this’ argument discards qualifiers [-fpermissive]
  529 |   tqMap.insert(s,m);
      |                   ^

----------------------------------------------------
/opt/Qt/5.13.0/gcc_64/include/QtCore/qmap.h:704: note:   in call to ‘QMap<K, V>::iterator QMap<K, V>::insert(const Key&, const T&) [with Key = QString; T = QMap<QString, QString>]’
  704 | Q_INLINE_TEMPLATE typename QMap<Key, T>::iterator QMap<Key, T>::insert(const Key &akey, const T &avalue)
      |                                                   ^~~~~~~~~~~~
------------------------------------------------------
error: no matching member function for call to 'insert'
---------------------------------------------------------
/opt/Qt/5.13.0/gcc_64/include/QtCore/qmap.h:586: candidate function not viable: 'this' argument has type 'const QMap<QString, QMap<QString, QString> >', but method is not marked const
-----------------------------------------------------------
/opt/Qt/5.13.0/gcc_64/include/QtCore/qmap.h:587: candidate function not viable: requires 3 arguments, but 2 were provided
---------------------------------------------------------------

0 个答案:

没有答案