<QForeach>
用于执行 for 循环的辅助宏。更多...
| Header: | #include <QForeach> |
宏
宏文档
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 。
© 2026 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.