Q_APPLICATION_STATIC: Assert existence of a QCoreApplication instance
Add asserting verifying that a QCoreApplication exists when the application static variable is dereferenced. This is a requirement described in the documentation. Added assertion makes invalid use much more visible. Without the assertion only a message about invalid nullptr used with QObject::connect() is emitted. This message is much less informative and does not cause tests to fail. Pick-to: 6.6 Change-Id: Id9d4a34679ca5aca93ee45ca2318d4ccf849887b Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Marc Mutz <marc.mutz@qt.io>
This commit is contained in:
parent
3ca6e7e6c7
commit
86d801e352
@ -51,6 +51,8 @@ template <typename QAS> struct ApplicationHolder
|
|||||||
if (guard.loadRelaxed() == QtGlobalStatic::Uninitialized) {
|
if (guard.loadRelaxed() == QtGlobalStatic::Uninitialized) {
|
||||||
QAS::innerFunction(&storage);
|
QAS::innerFunction(&storage);
|
||||||
const auto *app = QCoreApplication::instance();
|
const auto *app = QCoreApplication::instance();
|
||||||
|
Q_ASSERT_X(app, Q_FUNC_INFO,
|
||||||
|
"The application static was used without a QCoreApplication instance");
|
||||||
QObject::connect(app, &QObject::destroyed, app, reset, Qt::DirectConnection);
|
QObject::connect(app, &QObject::destroyed, app, reset, Qt::DirectConnection);
|
||||||
guard.storeRelease(QtGlobalStatic::Initialized);
|
guard.storeRelease(QtGlobalStatic::Initialized);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user