QGuiApplication: check return value of platformTheme::palette()
Under some circumstances (e.g. setDesktopSettingsAware(false) on windows) it may happen that the call to platformTheme::palette() returns a nullptr which is not checked before dereferencing the pointer. Therefore add a check for this to avoid a crash. Fixes: QTBUG-111527 Change-Id: I6443d5d1a9b813f499d8f65b4fee55b0b8299b16 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
parent
6e8563fb2d
commit
6259f4e7b4
@ -3502,7 +3502,8 @@ bool QGuiApplicationPrivate::setPalette(const QPalette &palette)
|
|||||||
*/
|
*/
|
||||||
QPalette QGuiApplicationPrivate::basePalette() const
|
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)
|
void QGuiApplicationPrivate::handlePaletteChanged(const char *className)
|
||||||
|
@ -47,6 +47,7 @@ private slots:
|
|||||||
void changeFocusWindow();
|
void changeFocusWindow();
|
||||||
void keyboardModifiers();
|
void keyboardModifiers();
|
||||||
void palette();
|
void palette();
|
||||||
|
void paletteNoCrash();
|
||||||
void font();
|
void font();
|
||||||
void modalWindow();
|
void modalWindow();
|
||||||
void quitOnLastWindowClosed();
|
void quitOnLastWindowClosed();
|
||||||
@ -552,6 +553,15 @@ void tst_QGuiApplication::palette()
|
|||||||
QCOMPARE(QGuiApplication::palette(), QPalette());
|
QCOMPARE(QGuiApplication::palette(), QPalette());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_QGuiApplication::paletteNoCrash()
|
||||||
|
{
|
||||||
|
QGuiApplication::setDesktopSettingsAware(false);
|
||||||
|
int argc = 1;
|
||||||
|
char *argv[] = { const_cast<char*>("tst_qguiapplication") };
|
||||||
|
// this would crash on windows (QTBUG-111527)
|
||||||
|
QGuiApplication a(argc, argv);
|
||||||
|
}
|
||||||
|
|
||||||
void tst_QGuiApplication::font()
|
void tst_QGuiApplication::font()
|
||||||
{
|
{
|
||||||
int argc = 1;
|
int argc = 1;
|
||||||
|
Loading…
Reference in New Issue
Block a user