<QForeach> Proxy Page

Macros

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

Macro Documentation

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 variable.

Note: 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

Same as forever.

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

See also 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 The foreach Keyword for details.

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

CONFIG += no_keywords

Note: 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.

Example:

forever {
    ...
}

It is equivalent to for (;;).

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

CONFIG += no_keywords

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

See also Q_FOREVER.

© 2023 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.