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

相关推荐
岁忧3 小时前
GoLang五种字符串拼接方式详解
开发语言·爬虫·golang
tyatyatya3 小时前
MATLAB基础数据类型教程:数值型/字符型/逻辑型/结构体/元胞数组全解析
开发语言·matlab
心无旁骛~4 小时前
python多进程和多线程问题
开发语言·python
星云数灵4 小时前
使用Anaconda管理Python环境:安装与验证Pandas、NumPy、Matplotlib
开发语言·python·数据分析·pandas·教程·环境配置·anaconda
kaikaile19954 小时前
基于遗传算法的车辆路径问题(VRP)解决方案MATLAB实现
开发语言·人工智能·matlab
四问四不知5 小时前
Rust语言进阶(结构体)
开发语言·后端·rust
q***9945 小时前
index.php 和 php
开发语言·php
oioihoii5 小时前
C++网络编程:从Socket混乱到优雅Reactor的蜕变之路
开发语言·网络·c++
笨鸟要努力5 小时前
Qt C++ windows 设置系统时间
c++·windows·qt
笙年5 小时前
JavaScript Promise,包括构造函数、对象方法和类方法
开发语言·javascript·ecmascript