当前位置:网站首页>Qt foreach关键字
Qt foreach关键字
2022-06-29 06:37:00 【Mr.codeee】
1.简介
foreach关键字用来遍历容器中的所有项。
foreach是QtGlobal头文件中定义的一个宏,用法如下:
使用foreach的代码比使用迭代器更简洁。
2.使用示例
2.1遍历一个QLinkedList<QString>
QLinkedList<QString> list;
...
QString str;
foreach (str, list)
qDebug() << str;
2.2跳出循环
和任何其他c++循环结构一样,你可以在foreach循环体周围使用大括号,你可以使用break离开循环。
QLinkedList<QString> list;
...
foreach (const QString &str, list) {
if (str.isEmpty())
break;
qDebug() << str;
}2.3遍历QMap keys
QMap<QString, int> map;
...
foreach (const QString &str, map.keys())
qDebug() << str << ':' << map.value(str);
边栏推荐
- Illustrate plug-in -- AI plug-in development -- creative plug-in -- astute graphics -- length and angle measurement function
- Ribbon 服务调用与负载均衡
- Print Yanghui triangle
- Case of single file component files
- Annual inventory review of Alibaba cloud's observable practices in 2021
- Why should enterprises do more application activities?
- Qt 程序打包发布-windeployqt工具
- Fault: display Storport driver out of date in component health
- Li Kou today's question -324 Swing sort II
- Share 10 interview questions related to JS promise
猜你喜欢

jetson tx2

How to fix Error: Failed to download metadata for repo ‘appstream‘: Cannot prepare internal mirrorli

二叉树的迭代法前序遍历的两种方法

Linux Installation redis

用机器人教育创造新一代生产和服务工具

数据库-同义词

Illustrate plug-in -- AI plug-in development -- creative plug-in -- astute graphics -- multi axis mirroring function

jetson tx2

Illustrate plug-in -- AI plug-in development -- creative plug-in -- astute graphics -- length and angle measurement function

Chapter IV introduction to FPGA development platform
随机推荐
package. Are you familiar with all configuration items and their usage of JSON
Difference between URI and URL
力扣每日一题-第30天-594.最长和谐子序列
String and variable are spliced into variable name
Open source 23 things shardingsphere and database mesh have to say
JDBC连接数据库,socket发送客户端。
Introduction to Ceres Quartet
力扣每日一题-第30天-1281.整数的各位积和之差
2022.02.14 - 239. A single element in an ordered array
Part 63 - interpreter and compiler adaptation (II)
[deep learning] - maze task learning I (to realize the random movement of agents)
VerilogA——动态比较器
WDCP accesses all paths that do not exist and jumps to the home page without returning 404
Mongodb paging method
RPC和RMI
Presto-Trial
MySQL add / delete / modify query SQL statement exercise yyds dry goods inventory
Games101 Lecture 10 geometry 1 Notes
Vite快速上手
Output of character pointer to string in C language