大家好,又见面了,我是你们的朋友全栈君。
本文主要总结Qt中键值对QMap的基本用法。
QMap是一个键值对类,跟标准C++的map类基本类似,声明原型如下:
QMap<T1,T2> map1
T1为键值对中的键key,T2为键值对中的值。通过键值对中的键可以搜索到值。一般来说,键值对中的键是唯一的,不可重复,而值没有要求,可以重复。并且QMap具有自动排序功能,对输入的键进行排序。
void Widget::on_pushButton_2_clicked()
{
QMap<DWORD64,QString> map1;
map1.insert(11,"name11");
map1.insert(2,"name2");
map1.insert(33,"name33");
map1.insert(4,"name4");
QMap<DWORD64,QString>::Iterator it=map1.begin();
while(it!=map1.end())
{
qDebug()<<it.key()<<"\t"<<it.value();
it++;
}
qDebug()<<"map1[2]=="<<map1[2];
if(map1.contains(4))
qDebug()<<map1.find(4).key();
}
参考内容:
https://www.cnblogs.com/judes/p/8066900.html
https://blog.csdn.net/u012927110/article/details/79750786
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/139572.html原文链接:https://javaforall.cn