QMap是一个以升序键顺序存储键值对的数据结构
-QMap原型为class QMap<K,T>模板
-QMap中键值对根据Key进行了排序
-QMap中Key类型必须重载operator <
QMap<QString, int> map;
map.insert("key 2", 2);
map.insert("key 0", 0);
map.insert("key 1", 1);
for(int i =1;i<3; i++)
{
qDebug() << map.value("key " + QString::number(i));
}
QList<QString> list = map.keys();
for(int i = 0; i<list.count(); i++)
{
qDebug() << list[i];
}
迭代器:
QMap<QString, int> map;
map["key 2"] = 2;
map["key 0"] = 0;
map["key 1"] = 1;
for(int i = 0; i<3; i++)
{
qDebug() << map["key " + QString::number(i)];
}
QMapIterator<QString, int> it(map);
while(it.hasNext())
{
it.next();
qDe