diff options
-rw-r--r-- | src/gui/image/qpixmap.cpp | 8 | ||||
-rw-r--r-- | tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp | 2 |
2 files changed, 9 insertions, 1 deletions
diff --git a/src/gui/image/qpixmap.cpp b/src/gui/image/qpixmap.cpp index 5b3e3985a7..1ea503a268 100644 --- a/src/gui/image/qpixmap.cpp +++ b/src/gui/image/qpixmap.cpp @@ -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; } /*! diff --git a/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp index b5a69d920a..fc011d726d 100644 --- a/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp +++ b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp @@ -1099,6 +1099,8 @@ void tst_QGuiApplication::staticFunctions() QGuiApplication::setQuitOnLastWindowClosed(true); QGuiApplication::quitOnLastWindowClosed(); QGuiApplication::applicationState(); + + QPixmap::defaultDepth(); } void tst_QGuiApplication::settableStyleHints_data() |