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 <giuseppe.dangelo@kdab.com>
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
This commit is contained in:
Friedemann Kleint 2018-09-24 15:25:32 +02:00
parent 4840668994
commit 91d43a48f7
5 changed files with 8 additions and 6 deletions

View File

@ -1598,7 +1598,7 @@ QGraphicsItem::~QGraphicsItem()
#ifndef QT_NO_GESTURES
if (d_ptr->isObject && !d_ptr->gestureContext.isEmpty()) {
QGraphicsObject *o = static_cast<QGraphicsObject *>(this);
if (QGestureManager *manager = QGestureManager::instance()) {
if (QGestureManager *manager = QGestureManager::instance(QGestureManager::DontForceCreation)) {
const auto types = d_ptr->gestureContext.keys(); // FIXME: iterate over the map directly?
for (Qt::GestureType type : types)
manager->cleanupCachedGestures(o, type);

View File

@ -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;
}

View File

@ -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);
}

View File

@ -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);

View File

@ -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);