QMap历遍value
时间: 2023-09-28 08:03:57 浏览: 145
要遍历QMap的value,可以使用QMap的values()函数获取一个QList,然后使用foreach循环遍历该列表。以下是一个示例代码:
```cpp
QMap<int, QString> map;
map.insert(1, "Apple");
map.insert(2, "Banana");
map.insert(3, "Cherry");
map.insert(4, "Grape");
foreach(QString value, map.values()) {
qDebug() << value;
}
```
这段代码将输出QMap中所有的value值:"Apple"、"Banana"、"Cherry"、"Grape"。\[2\]
#### 引用[.reference_title]
- *1* *3* [QMap遍历(修改)](https://blog.csdn.net/LebronBear/article/details/114819939)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* [QT 如何遍历序列容器(QVector|QMap|...)](https://blog.csdn.net/hellokandy/article/details/122581210)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文