Qt foreach用法
来源:互联网 发布:知乎如何玩 编辑:程序博客网 时间:2024/05/19 14:19
foreach(variables ,container)关键字是Qt对c++的一个扩展,主要用于按顺序历经容器(container)中的对象,例如,输出当前QT支持的数据库驱动:
01.
#include <QApplication>
02.
#include <QtSql/QSqlDatabase>
03.
#include <QDebug>
04.
#include <QStringList>
05.
06.
int
main(
int
argc,
char
*argv[])
07.
{
08.
QApplication a(argc,argv);
09.
qDebug()<<
"drivers:"
;
10.
QStringList drivers=QSqlDatabase::drivers();
11.
foreach(QString driver,drivers)
//遍历所支持的数据库驱动
12.
qDebug()<<driver;
13.
return
a.exec();
14.
}
QLinkedList<QString> list; ... QString str; foreach (str, list) qDebug() << str;
如果你想有序迭代容器中的所有项可以使用关键字foreach,这是qt对C++的特定补充,并通过预处理器实现。他的语法是:foreach (variable, container) +语句;这儿varible就相当于varible=container.item,只不过这个item会从container的头遍历到尾罢了。
QLinkedList<QString> list;
QLinkedListIterator<QString> i(list); while (i.hasNext()) qDebug() << i.next();这两个语句达到的目的是一样的
0 0
- Qt foreach用法
- 【Qt开发】foreach用法
- QT--foreach的用法
- Qt中foreach的用法
- Qt中foreach的用法
- Qt中foreach的用法
- Qt中foreach的用法
- Qt中foreach的用法
- Qt foreach 和 QTextCodec类的用法
- QT foreach
- foreach用法
- Foreach用法
- Foreach用法
- Foreach用法
- Foreach用法
- Foreach()用法
- foreach用法
- foreach用法
- CentOS7(64)环境下Hadoop2.6.0分布式部署说明
- Android获取系统服务getSystemService与getService区别
- scp 跨机远程拷贝
- c++第五次实验——数组分离
- ubuntu12.04下的samba使用方法
- Qt foreach用法
- Count and Say
- linux下安装python、scrapy、redis、mysql
- eclipseEE 配置android 环境
- iOS quartzCore第七章—— CAScrollLayer的运用
- ORA-28040: No matching authentication protocol exception
- Activity是如何接收到touch事件的(窗口与用户输入系统)
- wget 文件下载
- Region区域