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

相关推荐
AI玫瑰助手3 小时前
Python函数:默认参数的定义与注意事项
开发语言·python·信息可视化
油炸自行车3 小时前
Claude Code 错误:API Error: 400 Failed to deserialize the JSON body into the
开发语言·javascript·json·trae·claude code·api error 400
肩上风骋3 小时前
C++14特性
开发语言·c++·c++14特性
读书札记20223 小时前
Qt界面卡死问题探讨及解决方法
qt
JAVA社区5 小时前
Java高级全套教程(十)—— SpringCloudAlibaba超详细实战详解
java·开发语言·spring cloud·面试·职场和发展
弥树子5 小时前
踩坑记录:服务器内网调用接口,真实请求URL与官方公开URL不一致问题排查
开发语言·php
z落落5 小时前
C# ToCharArray + foreach遍历 + String与StringBuilder
开发语言·c#
学代码的真由酱5 小时前
Java多用户一对一网页聊天室-测试报告
java·开发语言·功能测试·测试
人道领域5 小时前
【LeetCode刷题日记】669.修剪二叉搜索树
开发语言·python·算法
xiaoshuaishuai86 小时前
C# AvaloniaUI动态显示图片
开发语言·c#