diff --git a/src/corelib/global/qglobalstatic.h b/src/corelib/global/qglobalstatic.h index cf96e5ae8e..098aee966b 100644 --- a/src/corelib/global/qglobalstatic.h +++ b/src/corelib/global/qglobalstatic.h @@ -145,8 +145,8 @@ protected: static QGlobalStatic> NAME; \ /**/ -#define Q_GLOBAL_STATIC(TYPE, NAME) \ - Q_GLOBAL_STATIC_WITH_ARGS(TYPE, NAME, ()) +#define Q_GLOBAL_STATIC(TYPE, NAME, ...) \ + Q_GLOBAL_STATIC_WITH_ARGS(TYPE, NAME, (__VA_ARGS__)) QT_END_NAMESPACE #endif // QGLOBALSTATIC_H diff --git a/src/corelib/global/qglobalstatic.qdoc b/src/corelib/global/qglobalstatic.qdoc index 99416ad102..1e3fc6f11c 100644 --- a/src/corelib/global/qglobalstatic.qdoc +++ b/src/corelib/global/qglobalstatic.qdoc @@ -26,7 +26,7 @@ ****************************************************************************/ /*! - \macro Q_GLOBAL_STATIC(Type, VariableName) + \macro Q_GLOBAL_STATIC(Type, VariableName, ...) \since 5.1 \relates QGlobalStatic @@ -36,6 +36,11 @@ will not increase the application or the library's load time. Additionally, the object is initialized in a thread-safe manner on all platforms. + Since Qt 6.3, this macro admits variadic arguments, which are used to + initialize the object, thus making the need for \l + Q_GLOBAL_STATIC_WITH_ARGS unnecessary. Please note the arguments do not + require an extra set of parentheses, unlike the older macro. + The typical use of this macro is as follows, in a global context (that is, outside of any function bodies): @@ -273,12 +278,13 @@ \endomit - \sa Q_GLOBAL_STATIC_WITH_ARGS(), QGlobalStatic + \sa Q_GLOBAL_STATIC_WITH_ARGS(), Q_APPLICATION_STATIC(), QGlobalStatic */ /*! \macro Q_GLOBAL_STATIC_WITH_ARGS(Type, VariableName, Arguments) \since 5.1 + \obsolete \relates QGlobalStatic Creates a global and static object of type \l QGlobalStatic, of name \a @@ -296,7 +302,12 @@ \endcode The \a Arguments macro parameter must always include the parentheses or, if - C++11 uniform initialization is allowed, the braces. + C++11 uniform initialization is allowed, the braces. The above call is + equivalent to + + \code + Q_GLOBAL_STATIC(MyType, staticType, 42, "Hello", "World") + \endcode Aside from the actual initialization of the contents with the supplied arguments, this macro behaves identically to Q_GLOBAL_STATIC(). Please diff --git a/src/corelib/kernel/qapplicationstatic.h b/src/corelib/kernel/qapplicationstatic.h index f34bd806a2..93a5062776 100644 --- a/src/corelib/kernel/qapplicationstatic.h +++ b/src/corelib/kernel/qapplicationstatic.h @@ -100,21 +100,18 @@ template struct ApplicationHolder }; } // namespace QtGlobalStatic -#define Q_APPLICATION_STATIC_WITH_ARGS(TYPE, NAME, ARGS) \ +#define Q_APPLICATION_STATIC(TYPE, NAME, ...) \ namespace { struct Q_QAS_ ## NAME { \ typedef TYPE QAS_Type; \ static void innerFunction(void *pointer) \ - noexcept(noexcept(std::remove_cv_t ARGS)) \ + noexcept(noexcept(std::remove_cv_t(__VA_ARGS__))) \ { \ - new (pointer) QAS_Type ARGS; \ + new (pointer) QAS_Type(__VA_ARGS__); \ } \ }; } \ static QGlobalStatic> NAME;\ /**/ -#define Q_APPLICATION_STATIC(TYPE, NAME) \ - Q_APPLICATION_STATIC_WITH_ARGS(TYPE, NAME, ()) - QT_END_NAMESPACE #endif // QAPPLICATIONSTATIC_H diff --git a/src/corelib/kernel/qapplicationstatic.qdoc b/src/corelib/kernel/qapplicationstatic.qdoc index 5903cdc20b..76507a2824 100644 --- a/src/corelib/kernel/qapplicationstatic.qdoc +++ b/src/corelib/kernel/qapplicationstatic.qdoc @@ -26,17 +26,18 @@ ****************************************************************************/ /*! - \macro Q_APPLICATION_STATIC(Type, VariableName) + \macro Q_APPLICATION_STATIC(Type, VariableName, ...) \since 6.3 \relates QGlobalStatic This macro extends Q_GLOBAL_STATIC and creates a global and static object - of type \l QGlobalStatic, of name \a VariableName and that behaves as a - pointer to \a Type, where the actual lifetime of the type is bound to the - QCoreApplication. The object created by Q_APPLICATION_STATIC initializes - itself on the first use, which means that it will not increase the application - or the library's load time. Additionally, the object is initialized in a - thread-safe manner on all platforms. + of type \l QGlobalStatic, of name \a VariableName, initialized by the + variadic arguments, and that behaves as a pointer to \a Type, where the + actual lifetime of the type is bound to the QCoreApplication. The object + created by Q_APPLICATION_STATIC initializes itself on the first use, which + means that it will not increase the application or the library's load time. + Additionally, the object is initialized in a thread-safe manner on all + platforms. In contrast to Q_GLOBAL_STATIC where the type is only meant to be destroyed at program exit, here the actual lifetime of the type is bound to the lifetime of @@ -56,9 +57,14 @@ outside of any function bodies): \code - Q_APPLICATION_STATIC(MyQObjectType, staticType) + Q_APPLICATION_STATIC(MyQObjectType, staticType, "some string", function()) \endcode + Do note that the arguments passed in variadic fashion to this macro are + evaluated every time the object is constructed, so in the above example, + the function \c{function} will be called more than once if the object is + recreated. + Aside from the value also being bound to the lifetime of the QCoreApplication, this macro behaves identically to Q_GLOBAL_STATIC(). Please see that macro's documentation for more information. @@ -99,38 +105,5 @@ \endomit - \sa Q_APPLICATION_STATIC_WITH_ARGS(), QGlobalStatic -*/ - -/*! - \macro Q_APPLICATION_STATIC_WITH_ARGS(Type, VariableName, Arguments) - \since 6.3 - \relates QGlobalStatic - - Creates a global and static object of type \l QGlobalStatic, of name \a - VariableName, initialized by the arguments \a Arguments and that behaves as - a pointer to \a Type, where the actual lifetime of the type is bound to the - QCoreApplication. The object created by Q_APPLICATION_STATIC_WITH_ARGS - initializes itself on the first use, which means that it will not increase - the application or the library's load time. Additionally, the object is - initialized in a thread-safe manner on all platforms. - - Since the value is bound to the QCoreApplication it should only ever be accessed, - if there is a valid QCoreApplication::instance(). - - The typical use of this macro is as follows, in a global context (that is, - outside of any function bodies): - - \code - Q_APPLICATION_STATIC_WITH_ARGS(MyQObjectType, staticType, (42, "Hello", "World")) - \endcode - - The \a Arguments macro parameter must always include the parentheses or, if - C++11 uniform initialization is allowed, the braces. - - Aside from the actual initialization of the contents with the supplied - arguments, this macro behaves identically to Q_APPLICATION_STATIC(). Please - see that macro's documentation for more information. - - \sa Q_APPLICATION_STATIC(), QGlobalStatic + \sa Q_GLOBAL_STATIC, QGlobalStatic */ diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp index 230aa40af6..b04f0cba7a 100644 --- a/src/network/access/qnetworkaccessmanager.cpp +++ b/src/network/access/qnetworkaccessmanager.cpp @@ -106,9 +106,9 @@ Q_APPLICATION_STATIC(QNetworkAccessFileBackendFactory, fileBackend) Q_GLOBAL_STATIC(QNetworkAccessDebugPipeBackendFactory, debugpipeBackend) #endif -Q_APPLICATION_STATIC_WITH_ARGS(QFactoryLoader, loader, - (QNetworkAccessBackendFactory_iid, - QLatin1String("/networkaccess"))) +Q_APPLICATION_STATIC(QFactoryLoader, loader, QNetworkAccessBackendFactory_iid, + QLatin1String("/networkaccess")) + #if defined(Q_OS_MACOS) bool getProxyAuth(const QString& proxyHostname, const QString &scheme, QString& username, QString& password) {