[QT] QMap使用详解

您所在的位置:网站首页 怎么修改map的value [QT] QMap使用详解

[QT] QMap使用详解

2023-08-11 17:41| 来源: 网络整理| 查看: 265

[QT] QMap使用详解 引言

​ QMap/QMultiMap属于关联式容器,其底层结构是通过二叉树实现,故其查找value的效率很快。QMap中的数据都是成对出现的,第一个称为key(键),第二个称value(键值)。

目录 实例化QMap对象插入数据移除数据遍历数据由键查找对应键值由键值查找键修改键值查找是否包含某个键获取所有的键和键值清楚数据一个键对应多个值QMultiMap遍历数据 实例化QMap对象 /* 创建QMap实例, 第一个参数为QString类型的键,第二个参数为int类型的值 */ QMap map; 插入数据 /* 插入数据 两种方式*/ map["math"] = 100; map.insert("English", 99); /* 推荐 */

打印输出: QMap((“English”, 99)(“math”, 100))

移除数据 /* 移除数据 */ map.remove("math");

打印输出:QMap((“English”, 99))

遍历数据 /* 遍历数据 (先随便插入几个)*/ map.insert("Math", 100); map.insert("Chinese", 98); map.insert("physical", 97); map.insert("chemical", 96); map.insert("biological", 95); /* 遍历数据要使用迭代器,QT提供了两种方式的迭代 */ /* 第一种是Java类型的迭代 */ QMapIterator iterator(map); while (iterator.hasNext()) { iterator.next(); qDebug() qDebug()


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3