当前位置:网站首页>QT中foreach的使用
QT中foreach的使用
2022-06-30 03:03:00 【my_angle2016】
示例:
在标准C++中,并没有foreach关键字,但是在QT中,可以使用这一个关键字,其主要原因是QT自己增加了这一个关键字,就像slots和signals、emit等一样。增加的foreach关键字在编译时会进行预处理。
用法:
foreach (varItem , Items) // foreach(variable ,container)其中,varItem(variable)是容器Items(container)中的一个项,相当于:variable=container.item 。遍历会从头遍历到尾。
如以下代码
QStringList slt = {"abc", "qwe", "upo"};
foreach(QString s , slt )
{
cout<<s<<endl;
}
// 输出结果为:
abc
qwe
upo QStringList test;
test.append("aaaa");
test.append("bbbb");
test.append("cccc");
QString tempa;
QString tempb;
int i = 0;
foreach(tempa, test)
{
qDebug() << tempa << endl;
if(1==i)
tempb = tempa;
i++;
}
qDebug() << tempb << endl;运行结果:

上段代码,清晰的揭示了,foreach函数的作用,即将test里面的元素,通过循环传递给tempa
边栏推荐
- 备忘一下es6的export/import和类继承的用法
- Cmake tutorial series -05- options and variables
- prompt learning 一个空格引发的血案
- Intel-Hex , Motorola S-Record 格式详细解析
- What kind of foreign exchange trading platform is regulated and safe?
- Distributed file system fastdfs
- C # basic learning (XIII) | breakpoint debugging
- Compile a DLL without import table
- zabbix 触发器详解
- How to prevent duplicate submission under concurrent requests
猜你喜欢

Simple custom MVC

HTA入门基础教程 | VBS脚本的GUI界面 HTA简明教程 ,附带完整历程及界面美化

Auto. JS learning notes 16: save to the mobile phone by project, instead of saving a single JS file every time, which is convenient for debugging and packaging

一篇文章带你入门vim

怎么使用Vant实现数据分页和下拉加载

golang bilibili直播彈幕姬

golang bilibili直播弹幕姬

GTK interface programming (I): Environment Construction

如何实现远程协同办公,收好这份攻略!

O & M (21) make winpe startup USB flash disk
随机推荐
Simple custom MVC
OP-diode-限制摆幅
快速排序、聚簇索引、寻找数据中第k大的值
LeetCode 3. Longest substring without duplicate characters
MySQL extracts strings from table fields
中断操作:AbortController学习笔记
什么是外链和内链?
O & M (20) make and start USB flash disk and install win10
Jvxetable sub table record loading completion event
Azure developer news flash list of events of developers in June
Servlet interview questions
【微信小程序】条件渲染 列表渲染 原来这样用?
The rigorous judgment of ID number is accurate to the last place in the team
2. successfully solved bug:exception when publishing [Failed to connect and initialize SSH connection...
备忘一下es6的export/import和类继承的用法
Utf8 error in Oracle migration of Jincang Kingbase database
Use compose to realize the effect of selecting movie seats by panning tickets
Sorting method of administrative route code letter + number
问题记录:fel_lib.c:26:10: fatal error: libusb.h: 没有那个文件或目录
可视化HTA窗体设计器-HtaMaker 界面介绍及使用方法,下载 | HTA VBS可视化脚本编写