diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index efda477569..abce792ad3 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -3502,7 +3502,8 @@ bool QGuiApplicationPrivate::setPalette(const QPalette &palette) */ QPalette QGuiApplicationPrivate::basePalette() const { - return platformTheme() ? *platformTheme()->palette() : Qt::gray; + const auto pf = platformTheme(); + return pf && pf->palette() ? *pf->palette() : Qt::gray; } void QGuiApplicationPrivate::handlePaletteChanged(const char *className) diff --git a/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp index 8542ce300f..2a2dbd0e48 100644 --- a/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp +++ b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp @@ -47,6 +47,7 @@ private slots: void changeFocusWindow(); void keyboardModifiers(); void palette(); + void paletteNoCrash(); void font(); void modalWindow(); void quitOnLastWindowClosed(); @@ -552,6 +553,15 @@ void tst_QGuiApplication::palette() QCOMPARE(QGuiApplication::palette(), QPalette()); } +void tst_QGuiApplication::paletteNoCrash() +{ + QGuiApplication::setDesktopSettingsAware(false); + int argc = 1; + char *argv[] = { const_cast("tst_qguiapplication") }; + // this would crash on windows (QTBUG-111527) + QGuiApplication a(argc, argv); +} + void tst_QGuiApplication::font() { int argc = 1;