The <QtGlobal> header file includes an assortment of other headers.
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>¶
Header
Summary
<
QFlags
>Type-safe way of combining enum values
Qt’s implementation of foreach and forever loops
Typedef for a pointer-to-function type
For
Q_APPLICATION_STATIC
<
QGlobalStatic
>Thread-safe initialization of global static objects
Helpers for resolving member function overloads
<
QSysInfo
>A helper class to get system information
Helpers to get type information
Q_ASSERT
and other runtime checksQt class helper macros
Compiler-specific macro definitions
Deprecation helper macros
Helpers for working with environment variables
<QtExceptionHandling>
Helpers for exception handling
Qt logging helpers
<QtMalloc>
Memory allocation helpers
Helpers for comparing values
Various numeric functions
Helper preprocessor macros
Architecture-specific macro definitions
Helpers for initializing and cleaning resources
Implementation of
qSwap()
Platform-specific macro definitions
Qt translation helpers
Qt type traits
Qt fundamental type declarations
QT_VERSION_CHECK
and related checks
QT_VERSION_STR
andqVersion()
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.
Version
Disabled APIs
6.0.0
foreach (see
QT_NO_FOREACH
)6.0.0
QString
conversions towardsconst char *
/QByteArray
(seeQT_NO_CAST_TO_ASCII
)6.0.0
QByteArray
implicit conversions towardsconst char *
(seeQT_NO_CAST_FROM_BYTEARRAY
)6.0.0
QUrl
implicit conversions fromQString
(seeQT_NO_URL_CAST_FROM_STRING
)6.0.0
Allowing narrowing conversions in signal-slot connections (see
QT_NO_NARROWING_CONVERSIONS_IN_CONNECT
)6.0.0
Java-style iterators for Qt containers
6.6.0
The
qExchange()
function (seeQT_NO_QEXCHANGE
)6.7.0
Overloads of
connect
that do not take a context object (seeQT_NO_CONTEXTLESS_CONNECT
)6.8.0
The qAsConst() function (see
QT_NO_QASCONST
)6.8.0
File-related I/O classes have their
open()
functions marked[[nodiscard]]
(seeQT_USE_NODISCARD_FILE_OPEN
)6.9.0
The qsnprintf() and qvnprintf() functions (see
QT_NO_QSNPRINTF
).
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.
See also
QT_DISABLE_DEPRECATED_UP_TO
QT_NO_KEYWORDS
QT_VERSION_CHECK
Defining this macro removes the availability of Qt’s foreach
loop.
See also
QT_NO_KEYWORDS
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.
See also
QT_NO_FOREACH
Use std::move
instead.
It expands to “std::move”.
qMove takes an rvalue reference to its parameter x
, and converts it to an xvalue.