<QForeach> Proxy Page

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

宏文档编制

Q_FOREACH ( variable , container )

Same as foreach( variable , container ).

This macro is available even when no_keywords is specified using the .pro file's CONFIG 变量。

注意: Since Qt 5.7, the use of this macro is discouraged. Use C++11 range-based for , possibly with std::as_const() , as needed.

Q_FOREVER

如同 forever .

This macro is available even when no_keywords is specified using the .pro file's CONFIG 变量。

另请参阅 foreach ().

foreach ( variable , container )

This macro is used to implement Qt's foreach loop. The variable parameter is a variable name or variable definition; the container parameter is a Qt container whose value type corresponds to the type of the variable. See foreach 关键字 了解细节。

If you're worried about namespace pollution, you can disable this macro by adding the following line to your .pro 文件:

CONFIG += no_keywords
					

注意: Since Qt 5.7, the use of this macro is discouraged. Use C++11 range-based for , possibly with std::as_const() , as needed.

forever

This macro is provided for convenience for writing infinite loops.

范例:

forever {
    ...
}
					

它相当于 for (;;) .

If you're worried about namespace pollution, you can disable this macro by adding the following line to your .pro 文件:

CONFIG += no_keywords
					

If using other build systems, you can add QT_NO_KEYWORDS to the list of pre-defined macros.

另请参阅 Q_FOREVER .