summaryrefslogtreecommitdiffstats
path: root/src/widgets
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@theqtcompany.com>2015-02-24 09:35:56 +0100
committerFriedemann Kleint <Friedemann.Kleint@theqtcompany.com>2015-02-27 06:02:44 +0000
commit175b12beba7bb4d1bf150c217afffc3d88801272 (patch)
treea81b924c20f9e911778f7334b2f6b76fb1a70600 /src/widgets
parent4e966497ce3674286f38faab68679201ec6ca22e (diff)
Prevent static functions of Q[Gui]Application from crashing if there is no instance.
Add tests. Task-number: QTBUG-44499 Change-Id: I160b089ad3f23ab71a87519e50f8a2ef5d2a4a6f Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/kernel/qapplication.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp
index e761520228..78c842f7e1 100644
--- a/src/widgets/kernel/qapplication.cpp
+++ b/src/widgets/kernel/qapplication.cpp
@@ -117,6 +117,14 @@ static void initResources()
QT_BEGIN_NAMESPACE
+// Helper macro for static functions to check on the existence of the application class.
+#define CHECK_QAPP_INSTANCE(...) \
+ if (Q_LIKELY(QCoreApplication::instance())) { \
+ } else { \
+ qWarning("Must construct a QApplication first."); \
+ return __VA_ARGS__; \
+ }
+
Q_CORE_EXPORT void qt_call_post_routines();
QApplicationPrivate *QApplicationPrivate::self = 0;
@@ -2855,6 +2863,7 @@ void QApplicationPrivate::sendSyntheticEnterLeave(QWidget *widget)
*/
QDesktopWidget *QApplication::desktop()
{
+ CHECK_QAPP_INSTANCE(Q_NULLPTR)
if (!qt_desktopWidget || // not created yet
!(qt_desktopWidget->windowType() == Qt::Desktop)) { // reparented away
qt_desktopWidget = new QDesktopWidget();
@@ -4110,6 +4119,7 @@ void QApplication::setEffectEnabled(Qt::UIEffect effect, bool enable)
*/
bool QApplication::isEffectEnabled(Qt::UIEffect effect)
{
+ CHECK_QAPP_INSTANCE(false)
return QColormap::instance().depth() >= 16
&& (QApplicationPrivate::enabledAnimations & QPlatformTheme::GeneralUiEffect)
&& (QApplicationPrivate::enabledAnimations & uiEffectToFlag(effect));