From 91d43a48f7307938624d4ab11e488494456646f5 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 24 Sep 2018 15:25:32 +0200 Subject: Prevent instantiation of QGestureManager in ~QWidget, ~QGraphicsItem() Debugging PYSIDE-815 revealed that QGestureManager is instantiated in the application destruction sequence. To prevent that, add a "force" parameter defaulting to true to QGestureManager::instance() and pass false in the destructors and QGestureManager::gesturePending(). Change-Id: I1b76173c926c2a156252b88832b032508d8e8a73 Reviewed-by: Giuseppe D'Angelo Reviewed-by: Richard Moe Gustavsen --- src/widgets/kernel/qapplication.cpp | 4 ++-- src/widgets/kernel/qgesturemanager.cpp | 2 +- src/widgets/kernel/qgesturemanager_p.h | 4 +++- src/widgets/kernel/qwidget.cpp | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) (limited to 'src/widgets/kernel') diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp index 10ded6e34f..45b98e9475 100644 --- a/src/widgets/kernel/qapplication.cpp +++ b/src/widgets/kernel/qapplication.cpp @@ -4521,12 +4521,12 @@ void QApplicationPrivate::notifyDragStarted(const QDrag *drag) #endif // QT_CONFIG(draganddrop) #ifndef QT_NO_GESTURES -QGestureManager* QGestureManager::instance() +QGestureManager* QGestureManager::instance(InstanceCreation ic) { QApplicationPrivate *qAppPriv = QApplicationPrivate::instance(); if (!qAppPriv) return 0; - if (!qAppPriv->gestureManager) + if (!qAppPriv->gestureManager && ic == ForceCreation) qAppPriv->gestureManager = new QGestureManager(qApp); return qAppPriv->gestureManager; } diff --git a/src/widgets/kernel/qgesturemanager.cpp b/src/widgets/kernel/qgesturemanager.cpp index 5bf66d68e3..c4188044cf 100644 --- a/src/widgets/kernel/qgesturemanager.cpp +++ b/src/widgets/kernel/qgesturemanager.cpp @@ -773,7 +773,7 @@ void QGestureManager::recycle(QGesture *gesture) bool QGestureManager::gesturePending(QObject *o) { - const QGestureManager *gm = QGestureManager::instance(); + const QGestureManager *gm = QGestureManager::instance(DontForceCreation); return gm && gm->m_gestureOwners.key(o); } diff --git a/src/widgets/kernel/qgesturemanager_p.h b/src/widgets/kernel/qgesturemanager_p.h index 3df80bab55..3a5c9822eb 100644 --- a/src/widgets/kernel/qgesturemanager_p.h +++ b/src/widgets/kernel/qgesturemanager_p.h @@ -81,7 +81,9 @@ public: bool filterEvent(QGraphicsObject *receiver, QEvent *event); #endif // QT_CONFIG(graphicsview) - static QGestureManager* instance(); // declared in qapplication.cpp + enum InstanceCreation { ForceCreation, DontForceCreation }; + + static QGestureManager *instance(InstanceCreation ic = ForceCreation); // declared in qapplication.cpp static bool gesturePending(QObject *o); void cleanupCachedGestures(QObject *target, Qt::GestureType type); diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index a1a861e216..09a08fac14 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -1572,7 +1572,7 @@ QWidget::~QWidget() #endif #ifndef QT_NO_GESTURES - if (QGestureManager *manager = QGestureManager::instance()) { + if (QGestureManager *manager = QGestureManager::instance(QGestureManager::DontForceCreation)) { // \forall Qt::GestureType type : ungrabGesture(type) (inlined) for (auto it = d->gestureContext.keyBegin(), end = d->gestureContext.keyEnd(); it != end; ++it) manager->cleanupCachedGestures(this, *it); -- cgit v1.2.3