From 3a2a18d64f96f54522869495eba33935374c1f1e Mon Sep 17 00:00:00 2001 From: Denis Dzyubenko Date: Tue, 27 Jul 2010 10:23:44 +0200 Subject: Check the gesturemanager pointer before accessing it. This fixes a crash when a static QWidget is destroyed after the QApplication object. Task-number: QTBUG-12025 Reviewed-by: Zeno Albisser (cherry picked from commit 475a3c275ba173cb130a838b6053cb45d405887e) --- src/gui/graphicsview/qgraphicsitem.cpp | 7 ++++--- src/gui/kernel/qapplication.cpp | 10 ++++++---- src/gui/kernel/qwidget.cpp | 4 ++-- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp index cd03eeb..adccd86 100644 --- a/src/gui/graphicsview/qgraphicsitem.cpp +++ b/src/gui/graphicsview/qgraphicsitem.cpp @@ -1437,9 +1437,10 @@ QGraphicsItem::~QGraphicsItem() #ifndef QT_NO_GESTURES if (d_ptr->isObject && !d_ptr->gestureContext.isEmpty()) { QGraphicsObject *o = static_cast(this); - QGestureManager *manager = QGestureManager::instance(); - foreach (Qt::GestureType type, d_ptr->gestureContext.keys()) - manager->cleanupCachedGestures(o, type); + if (QGestureManager *manager = QGestureManager::instance()) { + foreach (Qt::GestureType type, d_ptr->gestureContext.keys()) + manager->cleanupCachedGestures(o, type); + } } #endif diff --git a/src/gui/kernel/qapplication.cpp b/src/gui/kernel/qapplication.cpp index ccfe88c..5f256d5 100644 --- a/src/gui/kernel/qapplication.cpp +++ b/src/gui/kernel/qapplication.cpp @@ -5786,10 +5786,12 @@ Q_GUI_EXPORT void qt_translateRawTouchEvent(QWidget *window, #ifndef QT_NO_GESTURES QGestureManager* QGestureManager::instance() { - QApplicationPrivate *qAppPriv = QApplicationPrivate::instance(); - if (!qAppPriv->gestureManager) - qAppPriv->gestureManager = new QGestureManager(qApp); - return qAppPriv->gestureManager; + if (QApplicationPrivate *qAppPriv = QApplicationPrivate::instance()) { + if (!qAppPriv->gestureManager) + qAppPriv->gestureManager = new QGestureManager(qApp); + return qAppPriv->gestureManager; + } + return 0; } #endif // QT_NO_GESTURES diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp index 233df15..1b8c091 100644 --- a/src/gui/kernel/qwidget.cpp +++ b/src/gui/kernel/qwidget.cpp @@ -12047,8 +12047,8 @@ void QWidget::ungrabGesture(Qt::GestureType gesture) { Q_D(QWidget); if (d->gestureContext.remove(gesture)) { - QGestureManager *manager = QGestureManager::instance(); - manager->cleanupCachedGestures(this, gesture); + if (QGestureManager *manager = QGestureManager::instance()) + manager->cleanupCachedGestures(this, gesture); } } #endif // QT_NO_GESTURES -- cgit v0.12