QMap中的insert和insertMulti的区别
#include <QCoreApplication>
#include <QMap>
#include <QDebug>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QMap<int, QString> make;
make.insert(1, "11");
make.insert(2, "22");
make.insert(2, "2222");
make.insert(3, "33");
foreach (QString item, make)
{
qDebug() << item;
}
return a.exec();
}
- insertMulti对相同key不会重写value,而是重新创建一项
#include <QCoreApplication>
#include <QMap>
#include <QDebug>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QMap<int, QString> make;
make.insertMulti(1, "11");
make.insertMulti(2, "22");
make.insertMulti(2, "2222");
make.insertMulti(3, "33");
foreach (QString item, make)
{
qDebug() << item;
}
return a.exec();
}