<QForeach>代理页面

Q_FOREACH(variable, container)
Q_FOREVER
foreach(variable, container)
forever

宏文档

Q_FOREACH(variable, container)

与 foreach(variable,container) 相同。

即使使用.pro 文件的CONFIG 变量指定了no_keywords ,也可以使用该宏。

注意: 自 Qt 5.7 起,不鼓励使用此宏。请使用基于 C++11 范围的for ,必要时可使用std::as_const()

Q_FOREVER

forever 相同。

即使在使用.pro 文件的CONFIG 变量指定no_keywords 时,也可使用该宏。

另请参阅 foreach() 。

foreach(variable, container)

该宏用于实现 Qt 的foreach 循环。variable 参数是一个变量名或变量定义;container 参数是一个 Qt 容器,其值类型与变量类型相对应。详情请参阅foreach 关键字

如果担心命名空间污染,可以在.pro 文件中添加以下一行,禁用该宏:

CONFIG += no_keywords

注意: 自 Qt 5.7 起,不鼓励使用此宏。使用基于 C++11 范围的for ,必要时可使用std::as_const()

forever

提供该宏是为了方便编写无限循环。

举例说明:

forever {
    ...
}

它等同于for (;;)

如果担心命名空间污染,可在.pro 文件中添加以下一行,禁用该宏:

CONFIG += no_keywords

如果使用其他构建系统,可以将QT_NO_KEYWORDS 添加到预定义宏列表中。

另请参见 Q_FOREVER

© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.