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博客

相关推荐
临床数据科学和人工智能兴趣组10 分钟前
在R语言中, 使用 as.factor() 函数转换数值型变量
开发语言·r语言
andyweike3 小时前
php笔记
开发语言·笔记·php
Circ.4 小时前
Python 调试 Litellm 本地大模型接口:模型列表与对话接口实操踩坑记录
开发语言·python
现任明教教主~6 小时前
Thinkphp站群蜘蛛池SaaS系统YanyvSEO含多用户/积分/六大引擎计费/易支付对接
java·开发语言·spring
Zhou1411366 小时前
SpringSecurity_02_授权与高级功能
开发语言·python
码匠许师傅7 小时前
【C++三方组件】cpp-httplib:一个头文件起 HTTP 服务
开发语言·c++·http
小小小小钰儿8 小时前
1.5-Python网络编程
开发语言·网络·python·web安全·计算机·网络安全
hiahiahia1238 小时前
实现完整 Tool Dispatcher
开发语言·前端