diff options
author | Friedemann Kleint <Friedemann.Kleint@theqtcompany.com> | 2015-02-23 17:01:24 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@theqtcompany.com> | 2015-02-25 14:16:44 +0000 |
commit | 33403f2c79d678afc5b76add2c517d99b9708c32 (patch) | |
tree | 796fb3e1607a14b9e9e7f00a2e35a326ec083ba6 /src/gui | |
parent | 7bbde34ee012bbe90c4ce76736c6f71b16e64215 (diff) |
Fix crash when accessing QStyleHints before QGuiApplication is constructed.
Make styleHints a static member variable of QGuiApplicationPrivate and
fix accessor accordingly. Extend tst_QApplication::settableStyleHints()
to run without QApplication instance as well and add a similar test
to QGuiApplication.
Task-number: QTBUG-44499
Change-Id: I42b92ef38f7dd512d08d70accfa7dd4f09a22f01
Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/kernel/qguiapplication.cpp | 13 | ||||
-rw-r--r-- | src/gui/kernel/qguiapplication_p.h | 2 | ||||
-rw-r--r-- | src/gui/kernel/qstylehints.cpp | 5 |
3 files changed, 13 insertions, 7 deletions
diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 61addab9d6..d334bb72fa 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -163,6 +163,7 @@ QWindow *QGuiApplicationPrivate::focus_window = 0; static QBasicMutex applicationFontMutex; QFont *QGuiApplicationPrivate::app_font = 0; +QStyleHints *QGuiApplicationPrivate::styleHints = Q_NULLPTR; bool QGuiApplicationPrivate::obey_desktop_settings = true; QInputDeviceManager *QGuiApplicationPrivate::m_inputDeviceManager = 0; @@ -595,7 +596,6 @@ QGuiApplication::~QGuiApplication() QGuiApplicationPrivate::QGuiApplicationPrivate(int &argc, char **argv, int flags) : QCoreApplicationPrivate(argc, argv, flags), - styleHints(0), inputMethod(0), lastTouchType(QEvent::TouchEnd), ownGlobalShareContext(false) @@ -1349,7 +1349,8 @@ QGuiApplicationPrivate::~QGuiApplicationPrivate() cleanupThreadData(); - delete styleHints; + delete QGuiApplicationPrivate::styleHints; + QGuiApplicationPrivate::styleHints = Q_NULLPTR; delete inputMethod; qt_cleanupFontDatabase(); @@ -1717,7 +1718,7 @@ void QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::Mo } mouse_buttons = buttons = e->buttons; if (button & e->buttons) { - ulong doubleClickInterval = static_cast<ulong>(qApp->styleHints()->mouseDoubleClickInterval()); + ulong doubleClickInterval = static_cast<ulong>(QGuiApplication::styleHints()->mouseDoubleClickInterval()); doubleClick = e->timestamp - mousePressTime < doubleClickInterval && button == mousePressButton; type = frameStrut ? QEvent::NonClientAreaMouseButtonPress : QEvent::MouseButtonPress; mousePressTime = e->timestamp; @@ -3294,9 +3295,9 @@ void QGuiApplication::restoreOverrideCursor() */ QStyleHints *QGuiApplication::styleHints() { - if (!qGuiApp->d_func()->styleHints) - qGuiApp->d_func()->styleHints = new QStyleHints(); - return qGuiApp->d_func()->styleHints; + if (!QGuiApplicationPrivate::styleHints) + QGuiApplicationPrivate::styleHints = new QStyleHints(); + return QGuiApplicationPrivate::styleHints; } /*! diff --git a/src/gui/kernel/qguiapplication_p.h b/src/gui/kernel/qguiapplication_p.h index ddbc446759..0c00e06499 100644 --- a/src/gui/kernel/qguiapplication_p.h +++ b/src/gui/kernel/qguiapplication_p.h @@ -218,7 +218,7 @@ public: static QFont *app_font; - QStyleHints *styleHints; + static QStyleHints *styleHints; static bool obey_desktop_settings; QInputMethod *inputMethod; diff --git a/src/gui/kernel/qstylehints.cpp b/src/gui/kernel/qstylehints.cpp index a0f98383ff..b7af2e759f 100644 --- a/src/gui/kernel/qstylehints.cpp +++ b/src/gui/kernel/qstylehints.cpp @@ -35,6 +35,7 @@ #include <qpa/qplatformintegration.h> #include <qpa/qplatformtheme.h> #include <private/qguiapplication_p.h> +#include <qdebug.h> QT_BEGIN_NAMESPACE @@ -46,6 +47,10 @@ static inline QVariant hint(QPlatformIntegration::StyleHint h) static inline QVariant themeableHint(QPlatformTheme::ThemeHint th, QPlatformIntegration::StyleHint ih) { + if (!QCoreApplication::instance()) { + qWarning() << "Must construct a QGuiApplication before accessing a platform theme hint."; + return QVariant(); + } if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) { const QVariant themeHint = theme->themeHint(th); if (themeHint.isValid()) |