Fix crash if QPixmap::defaultDepth() is called when no QGuiApplication
This static method can be called before QGuiApplication is created. At that point there is yet no primary screen, so the implementation needs to guard against dereferencing a nullptr. Task-number: QTBUG-67309 Change-Id: I6b7b9e97b1c3c79bf2f9c6d6247c3b10f39f7a55 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
This commit is contained in:
parent
e8733ffc51
commit
7f782e1fc4
@ -1467,12 +1467,18 @@ QBitmap QPixmap::mask() const
|
||||
|
||||
On all platforms the depth of the primary screen will be returned.
|
||||
|
||||
\note QGuiApplication must be created before calling this function.
|
||||
|
||||
\sa depth(), QColormap::depth(), {QPixmap#Pixmap Information}{Pixmap Information}
|
||||
|
||||
*/
|
||||
int QPixmap::defaultDepth()
|
||||
{
|
||||
return QGuiApplication::primaryScreen()->depth();
|
||||
QScreen *primary = QGuiApplication::primaryScreen();
|
||||
if (Q_LIKELY(primary))
|
||||
return primary->depth();
|
||||
qWarning("QPixmap: QGuiApplication must be created before calling defaultDepth().");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -1099,6 +1099,8 @@ void tst_QGuiApplication::staticFunctions()
|
||||
QGuiApplication::setQuitOnLastWindowClosed(true);
|
||||
QGuiApplication::quitOnLastWindowClosed();
|
||||
QGuiApplication::applicationState();
|
||||
|
||||
QPixmap::defaultDepth();
|
||||
}
|
||||
|
||||
void tst_QGuiApplication::settableStyleHints_data()
|
||||
|
Loading…
Reference in New Issue
Block a user