From 5b4e57778aa9712deb5195d1c294f99192d982e8 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sun, 23 Mar 2025 22:35:32 +0100 Subject: [PATCH] tst_QGraphicsItem: fix leak of m_touchDevice The result of QTest::createTouchScreen() needs to be deleted by the caller, and this test didn't do that. To fix, put the object into a unique_ptr. Amends 982b70d37db337b2c57a3cfce0f24c3d00a598d6, though the code it replaced seems to have had the same problem. Pick-to: 6.8 6.5 5.15 Change-Id: I361a0b37b717ac543b003fb48a4a6934b6d79a03 Reviewed-by: Friedemann Kleint (cherry picked from commit e9a7c4a224a5859fb954b149ea0a0d3b0e4ada13) Reviewed-by: Qt Cherry-pick Bot --- .../qgraphicsitem/tst_qgraphicsitem.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp index 35356adcfcf..f01031db2c5 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp @@ -469,7 +469,7 @@ private slots: private: GraphicsItems paintedItems; - QPointingDevice *m_touchDevice = QTest::createTouchDevice(); + std::unique_ptr m_touchDevice{QTest::createTouchDevice()}; }; void tst_QGraphicsItem::cleanup() @@ -11077,13 +11077,14 @@ void tst_QGraphicsItem::touchEventPropagation() view.setSceneRect(touchEventReceiver->boundingRect()); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); - QInputDevicePrivate::get(m_touchDevice)->setAvailableVirtualGeometry(view.screen()->geometry()); + QInputDevicePrivate::get(m_touchDevice.get()) + ->setAvailableVirtualGeometry(view.screen()->geometry()); QCOMPARE(touchEventReceiver->touchBeginEventCount(), 0); const QPointF scenePos = view.sceneRect().center(); sendMousePress(&scene, scenePos); - QMutableTouchEvent touchBegin(QEvent::TouchBegin, m_touchDevice, Qt::NoModifier, + QMutableTouchEvent touchBegin(QEvent::TouchBegin, m_touchDevice.get(), Qt::NoModifier, createTouchPoints(view, scenePos, QSizeF(10, 10))); touchBegin.setTarget(view.viewport()); @@ -11137,11 +11138,12 @@ void tst_QGraphicsItem::touchEventTransformation() view.setTransform(viewTransform); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); - QInputDevicePrivate::get(m_touchDevice)->setAvailableVirtualGeometry(view.screen()->geometry()); + QInputDevicePrivate::get(m_touchDevice.get()) + ->setAvailableVirtualGeometry(view.screen()->geometry()); QCOMPARE(touchEventReceiver->touchBeginEventCount(), 0); - QMutableTouchEvent touchBegin(QEvent::TouchBegin, m_touchDevice, Qt::NoModifier, + QMutableTouchEvent touchBegin(QEvent::TouchBegin, m_touchDevice.get(), Qt::NoModifier, createTouchPoints(view, touchScenePos, ellipseDiameters)); touchBegin.setTarget(view.viewport()); QCoreApplication::sendEvent(&scene, &touchBegin); @@ -11155,7 +11157,7 @@ void tst_QGraphicsItem::touchEventTransformation() COMPARE_POINTF(touchBeginPoint.position(), expectedItemPos); COMPARE_SIZEF(touchBeginPoint.ellipseDiameters(), ellipseDiameters); // Must remain untransformed - QMutableTouchEvent touchUpdate(QEvent::TouchUpdate, m_touchDevice, Qt::NoModifier, + QMutableTouchEvent touchUpdate(QEvent::TouchUpdate, m_touchDevice.get(), Qt::NoModifier, createTouchPoints(view, touchScenePos, ellipseDiameters, QEventPoint::State::Updated)); touchUpdate.setTarget(view.viewport());