diff options
author | Denis Dzyubenko <denis.dzyubenko@nokia.com> | 2010-01-06 17:16:27 (GMT) |
---|---|---|
committer | Jesper Thomschutz <jesper.thomschutz@nokia.com> | 2010-01-13 09:47:39 (GMT) |
commit | 09b7479c73d3da868c04752c621af30f505559dc (patch) | |
tree | 89b12b07d3ec20ad2e23f88e16817f42c57b210a | |
parent | 6649a1f1340a6e3bf6fcc61e641add504797d77a (diff) | |
download | Qt-09b7479c73d3da868c04752c621af30f505559dc.zip Qt-09b7479c73d3da868c04752c621af30f505559dc.tar.gz Qt-09b7479c73d3da868c04752c621af30f505559dc.tar.bz2 |
Fixes a crash when destroying and creating QApplication.
Moved the gestureManager pointer to a QApplicationPrivate to make sure if
QApplication object is destroyed, QGestureManager pointer is set to zero.
Task-number: QTBUG-7029
Reviewed-by: Thiago
(cherry picked from commit 828b1299e1ecb2da23799a2e49370e00dcf9c126)
-rw-r--r-- | src/gui/graphicsview/qgraphicsscene.cpp | 10 | ||||
-rw-r--r-- | src/gui/kernel/qapplication.cpp | 15 | ||||
-rw-r--r-- | src/gui/kernel/qapplication_p.h | 2 | ||||
-rw-r--r-- | src/gui/kernel/qgesturemanager.cpp | 9 | ||||
-rw-r--r-- | src/gui/kernel/qgesturemanager_p.h | 4 |
5 files changed, 21 insertions, 19 deletions
diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp index 16ce26a..83ef110 100644 --- a/src/gui/graphicsview/qgraphicsscene.cpp +++ b/src/gui/graphicsview/qgraphicsscene.cpp @@ -1136,8 +1136,9 @@ bool QGraphicsScenePrivate::filterEvent(QGraphicsItem *item, QEvent *event) bool QGraphicsScenePrivate::sendEvent(QGraphicsItem *item, QEvent *event) { if (QGraphicsObject *object = item->toGraphicsObject()) { - if (qt_gestureManager) { - if (qt_gestureManager->filterEvent(object, event)) + QGestureManager *gestureManager = QApplicationPrivate::instance()->gestureManager; + if (gestureManager) { + if (gestureManager->filterEvent(object, event)) return true; } } @@ -6157,9 +6158,10 @@ void QGraphicsScenePrivate::cancelGesturesForChildren(QGesture *original, QWidge } } - Q_ASSERT(qt_gestureManager); // it would be very odd if we got called without a manager. + QGestureManager *gestureManager = QApplicationPrivate::instance()->gestureManager; + Q_ASSERT(gestureManager); // it would be very odd if we got called without a manager. for (setIter = canceledGestures.begin(); setIter != canceledGestures.end(); ++setIter) { - qt_gestureManager->recycle(*setIter); + gestureManager->recycle(*setIter); gestureTargets.remove(*setIter); } } diff --git a/src/gui/kernel/qapplication.cpp b/src/gui/kernel/qapplication.cpp index df36466..fb923be 100644 --- a/src/gui/kernel/qapplication.cpp +++ b/src/gui/kernel/qapplication.cpp @@ -177,6 +177,7 @@ QApplicationPrivate::QApplicationPrivate(int &argc, char **argv, QApplication::T directPainters = 0; #endif + gestureManager = 0; gestureWidget = 0; if (!self) @@ -3632,7 +3633,7 @@ bool QApplication::notify(QObject *receiver, QEvent *e) } // walk through parents and check for gestures - if (qt_gestureManager) { + if (d->gestureManager) { switch (e->type()) { case QEvent::Paint: case QEvent::MetaCall: @@ -3664,13 +3665,13 @@ bool QApplication::notify(QObject *receiver, QEvent *e) break; default: if (receiver->isWidgetType()) { - if (qt_gestureManager->filterEvent(static_cast<QWidget *>(receiver), e)) + if (d->gestureManager->filterEvent(static_cast<QWidget *>(receiver), e)) return true; } else { // a special case for events that go to QGesture objects. // We pass the object to the gesture manager and it'll figure // out if it's QGesture or not. - if (qt_gestureManager->filterEvent(receiver, e)) + if (d->gestureManager->filterEvent(receiver, e)) return true; } } @@ -5678,6 +5679,14 @@ Q_GUI_EXPORT void qt_translateRawTouchEvent(QWidget *window, QApplicationPrivate::translateRawTouchEvent(window, deviceType, touchPoints); } +QGestureManager* QGestureManager::instance() +{ + QApplicationPrivate *qAppPriv = QApplicationPrivate::instance(); + if (!qAppPriv->gestureManager) + qAppPriv->gestureManager = new QGestureManager(qApp); + return qAppPriv->gestureManager; +} + QT_END_NAMESPACE #include "moc_qapplication.cpp" diff --git a/src/gui/kernel/qapplication_p.h b/src/gui/kernel/qapplication_p.h index b004f95..e865399 100644 --- a/src/gui/kernel/qapplication_p.h +++ b/src/gui/kernel/qapplication_p.h @@ -84,6 +84,7 @@ class QInputContext; class QObject; class QWidget; class QSocketNotifier; +class QGestureManager; extern bool qt_is_gui_used; #ifndef QT_NO_CLIPBOARD @@ -509,6 +510,7 @@ public: void sendSyntheticEnterLeave(QWidget *widget); #endif + QGestureManager *gestureManager; QWidget *gestureWidget; QMap<int, QWeakPointer<QWidget> > widgetForTouchPointId; diff --git a/src/gui/kernel/qgesturemanager.cpp b/src/gui/kernel/qgesturemanager.cpp index 4757656..a4604bf 100644 --- a/src/gui/kernel/qgesturemanager.cpp +++ b/src/gui/kernel/qgesturemanager.cpp @@ -67,15 +67,6 @@ QT_BEGIN_NAMESPACE -QGestureManager *qt_gestureManager = 0; - -QGestureManager* QGestureManager::instance() -{ - if (!qt_gestureManager) - qt_gestureManager = new QGestureManager(qApp); - return qt_gestureManager; -} - QGestureManager::QGestureManager(QObject *parent) : QObject(parent), state(NotGesture), m_lastCustomGestureId(0) { diff --git a/src/gui/kernel/qgesturemanager_p.h b/src/gui/kernel/qgesturemanager_p.h index 0e1f153..9c4658c 100644 --- a/src/gui/kernel/qgesturemanager_p.h +++ b/src/gui/kernel/qgesturemanager_p.h @@ -78,7 +78,7 @@ public: bool filterEvent(QGraphicsObject *receiver, QEvent *event); #endif //QT_NO_GRAPHICSVIEW - static QGestureManager* instance(); + static QGestureManager* instance(); // declared in qapplication.cpp void cleanupCachedGestures(QObject *target, Qt::GestureType type); @@ -142,8 +142,6 @@ private: void cancelGesturesForChildren(QGesture *originatingGesture); }; -extern QGestureManager *qt_gestureManager; - QT_END_NAMESPACE #endif // QGESTUREMANAGER_P_H |