<QtGlobal> - Global Qt Declarations

The <QtGlobal> header file includes an assortment of other headers. More...

Header: #include <QtGlobal>


Detailed Description

Up to Qt 6.5, most Qt header files included <QtGlobal>. Before Qt 6.5, <QtGlobal> defined an assortment of global declarations. Most of these have moved, at Qt 6.5, to separate headers, so that source code can include only what it needs, rather than the whole assortment. For now, <QtGlobal> includes those other headers (see next section), but future releases of Qt may remove some of these headers from <QtGlobal> or condition their inclusion on a version check. Likewise, in future releases, some Qt headers that currently include <QtGlobal> may stop doing so. The hope is that this will improve compilation times by avoiding global declarations when they are not used.

List of Headers Extracted from <QtGlobal>

<QFlags>Type-safe way of combining enum values
<QForeach>Qt's implementation of foreach and forever loops
<QFunctionPointer>Typedef for a pointer-to-function type
<QApplicationStatic>For Q_APPLICATION_STATIC
<QGlobalStatic>Thread-safe initialization of global static objects
<QOverload>Helpers for resolving member function overloads
<QSysInfo>A helper class to get system information
<QTypeInfo>Helpers to get type information
<QtAssert>Q_ASSERT and other runtime checks
<QtClassHelperMacros>Qt class helper macros
<QtCompilerDetection>Compiler-specific macro definitions
<QtDeprecationMarkers>Deprecation helper macros
<QtEnvironmentVariables>Helpers for working with environment variables
<QtExceptionHandling>Helpers for exception handling
<QtLogging>Qt logging helpers
<QtMalloc>Memory allocation helpers
<QtMinMax>Helpers for comparing values
<QtNumeric>Various numeric functions
<QtPreprocessorSupport>Helper preprocessor macros
<QtProcessorDetection>Architecture-specific macro definitions
<QtResource>Helpers for initializing and cleaning resources
<QtSwap>Implementation of qSwap()
<QtSystemDetection>Platform-specific macro definitions
<QtTranslation>Qt translation helpers
<QtTypeTraits>Qt type traits
<QtTypes>Qt fundamental type declarations
<QtVersionChecks>QT_VERSION_CHECK and related checks
<QtVersion>QT_VERSION_STR and qVersion()

Macro Documentation


Defining this macro will disable a number of Qt APIs that are deemed suboptimal or dangerous.

This macro's value must be set to a Qt version, using QT_VERSION_CHECK's encoding. For instance, in order to set it to Qt 6.6, define QT_ENABLE_STRICT_MODE_UP_TO=0x060600. This will disable only the APIs introduced in versions up to (and including) the specified Qt version.

If the QT_DISABLE_DEPRECATED_UP_TO macro is not defined, then QT_ENABLE_STRICT_MODE_UP_TO will define it as well, to the same value.

This macro should always be set to the minimum Qt version that your project wants to support.

The APIs disabled by this macro are listed in the table below, together with the minimum value to use in order to disable them.

VersionDisabled APIs
6.0.0foreach (see QT_NO_FOREACH)
6.0.0QString constructors from const char * (see QT_NO_CAST_FROM_ASCII)
6.0.0QString conversions towards const char * / QByteArray (see QT_NO_CAST_TO_ASCII)
6.0.0QByteArray implicit conversions towards const char * (see QT_NO_CAST_FROM_BYTEARRAY)
6.0.0QUrl implicit conversions from QString (see QT_NO_URL_CAST_FROM_STRING)
6.0.0Allowing narrowing conversions in signal-slot connections (see QT_NO_NARROWING_CONVERSIONS_IN_CONNECT)
6.0.0Java-style iterators for Qt containers
6.6.0The qExchange() function (see QT_NO_QEXCHANGE)
6.7.0Overloads of QObject::connect that do not take a context object (see QT_NO_CONTEXTLESS_CONNECT)
6.8.0The qAsConst() function (see QT_NO_QASCONST)
6.8.0File-related I/O classes have their open() functions marked [[nodiscard]] (see QT_USE_NODISCARD_FILE_OPEN)

Moreover, individual APIs may also get disabled as part of the setting of QT_DISABLE_DEPRECATED_UP_TO. Please refer to each class' documentation for more details.

This macro was introduced in Qt 6.8.


[since 6.0] QT_NO_FOREACH

Defining this macro removes the availability of Qt's foreach loop.

This macro was introduced in Qt 6.0.



Define this macro to disable the Qt-specific keywords that are usually enabled, such as signals and slots. Use Q_SIGNALS and Q_SLOTS instead.

Libraries should define this macro to make sure that they don't use the generic keywords without the Q_ prefix in their public headers.


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