foreach()
- 依次读取数组的每个元素
void testForeach(){
QStringList listTemp;
listTemp.append("aaa");
listTemp.append("bbb");
listTemp.append("ccc");
QString strTemp1;
QString strTemp2;
foreach(strTemp1,listTemp)
{
strTemp2= strTemp1;
qDebug()<<strTemp1;
}
}
- Qt中for()也有类似的用法
void testFor(){
QStringList listTemp;
listTemp.append("aaa");
listTemp.append("bbb");
listTemp.append("ccc");
for(QString strTemp1 : listTemp)
{
qDebug()<<strTemp1;
}
}
- 以上程序的运行结果一致,见下