diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2020-03-20 14:37:24 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2020-03-23 16:36:29 +0100 |
commit | 8aa13799516bb412908a5612da5ea5ba0972b998 (patch) | |
tree | 3ce19679fbf8071ab948646be9497f94132bdcd9 /src/quick/items/qquickevents.cpp | |
parent | 67b73ad00904981d001bd752feae39b73407c103 (diff) |
QQuickEvents: Delete pointer devices on shutdown
Letting them leak makes ASAN report false positives.
Change-Id: I59dfcdffa380294cada9b79c11af0faaab38e3a0
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'src/quick/items/qquickevents.cpp')
-rw-r--r-- | src/quick/items/qquickevents.cpp | 35 |
1 files changed, 25 insertions, 10 deletions
diff --git a/src/quick/items/qquickevents.cpp b/src/quick/items/qquickevents.cpp index 804c3a081e..9469a9a06c 100644 --- a/src/quick/items/qquickevents.cpp +++ b/src/quick/items/qquickevents.cpp @@ -580,8 +580,6 @@ Item { \sa QTouchDevice::capabilities */ -typedef QHash<const QTouchDevice *, QQuickPointerDevice *> PointerDeviceForTouchDeviceHash; -Q_GLOBAL_STATIC(PointerDeviceForTouchDeviceHash, g_touchDevices) struct ConstructableQQuickPointerDevice : public QQuickPointerDevice { @@ -591,14 +589,21 @@ struct ConstructableQQuickPointerDevice : public QQuickPointerDevice : QQuickPointerDevice(devType, pType, caps, maxPoints, buttonCount, name, uniqueId) {} }; + +template<typename Key> +struct PointerDeviceHash : public QHash<Key, ConstructableQQuickPointerDevice *> +{ + ~PointerDeviceHash() { qDeleteAll(*this); } +}; +using PointerDeviceForTouchDeviceHash = PointerDeviceHash<const QTouchDevice *>; +Q_GLOBAL_STATIC(PointerDeviceForTouchDeviceHash, g_touchDevices) Q_GLOBAL_STATIC_WITH_ARGS(ConstructableQQuickPointerDevice, g_genericMouseDevice, (QQuickPointerDevice::Mouse, QQuickPointerDevice::GenericPointer, QQuickPointerDevice::Position | QQuickPointerDevice::Scroll | QQuickPointerDevice::Hover, 1, 3, QLatin1String("core pointer"), 0)) - #if QT_CONFIG(tabletevent) -typedef QHash<qint64, QQuickPointerDevice *> PointerDeviceForDeviceIdHash; +using PointerDeviceForDeviceIdHash = PointerDeviceHash<qint64>; Q_GLOBAL_STATIC(PointerDeviceForDeviceIdHash, g_tabletDevices) #endif @@ -639,20 +644,28 @@ QQuickPointerDevice *QQuickPointerDevice::touchDevice(const QTouchDevice *d) qWarning() << "QQuickWindowPrivate::touchDevice: creating touch device from nullptr device in QTouchEvent"; } - QQuickPointerDevice *dev = new QQuickPointerDevice(type, QQuickPointerDevice::Finger, - caps, maximumTouchPoints, 0, name, 0); + ConstructableQQuickPointerDevice *dev = new ConstructableQQuickPointerDevice( + type, QQuickPointerDevice::Finger, caps, maximumTouchPoints, 0, name, 0); g_touchDevices->insert(d, dev); return dev; } const QTouchDevice *QQuickPointerDevice::qTouchDevice() const { - return g_touchDevices->key(const_cast<QQuickPointerDevice *>(this)); + for (auto it = g_touchDevices->constBegin(), end = g_touchDevices->constEnd(); it != end; ++it) { + if (it.value() == this) + return it.key(); + } + return nullptr; } QList<QQuickPointerDevice*> QQuickPointerDevice::touchDevices() { - return g_touchDevices->values(); + QList<QQuickPointerDevice *> result; + result.reserve(g_touchDevices->size()); + for (auto device : *g_touchDevices) + result.append(device); + return result; } QQuickPointerDevice *QQuickPointerDevice::genericMouseDevice() @@ -723,8 +736,10 @@ QQuickPointerDevice *QQuickPointerDevice::tabletDevice(const QTabletEvent *event break; } - QQuickPointerDevice *device = new QQuickPointerDevice(type, ptype, caps, 1, buttonCount, - QLatin1String("tablet tool ") + QString::number(event->uniqueId()), event->uniqueId()); + ConstructableQQuickPointerDevice *device = new ConstructableQQuickPointerDevice( + type, ptype, caps, 1, buttonCount, + QLatin1String("tablet tool ") + QString::number(event->uniqueId()), + event->uniqueId()); g_tabletDevices->insert(key, device); return device; |