QT foreach

原型:foreach(variable, container)

container:容器,即被遍历的对象

variable:当前元素,即遍历container过程中,当前的那个元素

代码:

复制代码
QStringList container = { "1", "2", "3" };//定义一个QStringList类型的数组,名字叫container
foreach(QString variable, container)//使用foreach遍历container
{

	qDebug() << variable.toLatin1().data();//每次遍历container的一个元素,输出到控制台
    qDebug() << variable;
}

结果:

参考:Qt foreach遍历 | 九七的Qt_qstringlist遍历-CSDN博客

如想了解 toLatin1可以参考:qt中的toUtf8, toLatin1, Local8bit编码问题-CSDN博客

相关推荐
李绍熹5 分钟前
C语言基础语法示例
c语言·开发语言
kiki-bf9 分钟前
使用python把图片转为word
开发语言·python·word
光羽隹衡17 分钟前
Python中的网络爬虫
开发语言·爬虫·python
不会写DN20 分钟前
fmt 包中的所有 Print 系列函数
开发语言·后端·golang·go
南棱笑笑生1 小时前
20251213给飞凌OK3588-C开发板适配Rockchip原厂的Buildroot【linux-6.1】系统时适配CTP触摸屏FT5X06
linux·c语言·开发语言·rockchip
kupeThinkPoem1 小时前
Qt中setSpacing函数介绍
qt
weixin_459548901 小时前
QT+Echarts初始示例
qt·echarts
兩尛2 小时前
高频提问部分
开发语言·后端·ruby
深蓝电商API2 小时前
企业级爬虫架构设计:任务调度、容错、重试、降重
开发语言·爬虫·ruby
芝麻开门-新起点2 小时前
第13-1章 Python地理空间开发
开发语言·python