summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel
diff options
context:
space:
mode:
authorEirik Aavitsland <eirik.aavitsland@qt.io>2020-02-07 16:00:00 +0100
committerEirik Aavitsland <eirik.aavitsland@qt.io>2020-02-13 11:53:08 +0100
commit8e74bf4d4aaaf582c70cbcb83caa237e2592e762 (patch)
tree16a5c9efa4b3e2a17014348a85e301c5bd09cbad /src/gui/kernel
parentcd02e29319508ea0e3b7c35f671433b056769f2e (diff)
Avoid dangling QGuiApplicationPrivate pointer
The static self pointer of QGuiApplicationPrivate was not reset at destruction (in constrast to the corresponding QGuiApplication::self). This could cause crashes when calling Qt API after QGuiApplication destruction. Fixing this revealed an issue with QGuiApplication::font(), which would assert QGuiApplicationPrivate::self. But the QApplication autotest actually calls this function with no QApplication instance. That autotest passes only coincidentally, since another QApplication instance has been created and deleted already, and the dangling self pointer of that instance was never reset. To improve the robustness of the api, replace the assert/crash with just a warning and return an "empty" QFont. (The assert was added for 5.0 for QTBUG-28306 in order to give a nicer warning when mixing QWidget and QtCore/GuiApplication. However it never got that effect in practice, since that issue was fixed at the same time by another, better patch for the duplicate bug QTBUG-28076). Fixes: QTBUG-81954 Change-Id: I3fa6cad1625a3e70631b5170d53119d63492b534 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/gui/kernel')
-rw-r--r--src/gui/kernel/qguiapplication.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp
index 1190bd1936..67b1ed15c5 100644
--- a/src/gui/kernel/qguiapplication.cpp
+++ b/src/gui/kernel/qguiapplication.cpp
@@ -1727,6 +1727,8 @@ QGuiApplicationPrivate::~QGuiApplicationPrivate()
window_list.clear();
screen_list.clear();
+
+ self = nullptr;
}
#if 0
@@ -3401,8 +3403,11 @@ void QGuiApplicationPrivate::applyWindowGeometrySpecificationTo(QWindow *window)
*/
QFont QGuiApplication::font()
{
- Q_ASSERT_X(QGuiApplicationPrivate::self, "QGuiApplication::font()", "no QGuiApplication instance");
const auto locker = qt_scoped_lock(applicationFontMutex);
+ if (!QGuiApplicationPrivate::self && !QGuiApplicationPrivate::app_font) {
+ qWarning("QGuiApplication::font(): no QGuiApplication instance and no application font set.");
+ return QFont(); // in effect: QFont((QFontPrivate*)nullptr), so no recursion
+ }
initFontUnlocked();
return *QGuiApplicationPrivate::app_font;
}