tst_QGraphicsWidget: fix memleak in implicitMouseGrabber()
If a QGraphicsItem is removed from a QGraphicsScene, it also gets un-parent-ed, and the caller of removeItem() is responsible for deleting the item henceforth. The test function neglected that, leaking the object. To fix, use a scope-guard to defer deletion of the object to the exit from the test function. This is the minimally-invasive fix. Amends the start of the public history. Pick-to: 6.8 6.5 5.15 Change-Id: Ie4f9be232674bba583f4a59908e42de096930136 Reviewed-by: Axel Spoerl <axel.spoerl@qt.io> (cherry picked from commit 156bd559231f06136bc368236675688b3c93d02a) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
6489fc1e52
commit
4a9782f628
@ -2290,6 +2290,7 @@ void tst_QGraphicsWidget::implicitMouseGrabber()
|
|||||||
QCOMPARE(widget2UngrabEventSpy.count(), 0);
|
QCOMPARE(widget2UngrabEventSpy.count(), 0);
|
||||||
|
|
||||||
scene.removeItem(widget);
|
scene.removeItem(widget);
|
||||||
|
const auto reaper = qScopeGuard([=] { delete widget; });
|
||||||
QCOMPARE(widgetUngrabEventSpy.count(), 4);
|
QCOMPARE(widgetUngrabEventSpy.count(), 4);
|
||||||
QCOMPARE(scene.mouseGrabberItem(), nullptr);
|
QCOMPARE(scene.mouseGrabberItem(), nullptr);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user