tst_QGraphicsGridLayout: fix memleak in removeItem()

The test function contains a negative test where we're trying to
remove an item that isn't in the layout.

Unfortunately, the object we're passing is heap-allocated and has no
parent, so was leaked.

To fix, pass the existing `widget` as a parent. This doesn't change
the test's outcome: Like in QWidget, a graphics-widget is not
automatically added to its parent's layout.

Amends the start of the public history.

Pick-to: 6.6 6.5 5.15
Change-Id: Ic110ea7b93aa0023c0903c776a30dc5c377ce0c5
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
(cherry picked from commit 4d0f979610b961e3dd4e86060fc05456c9d1447d)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2025-04-03 13:58:55 +02:00 committed by Qt Cherry-pick Bot
parent 13b833cd1a
commit f6d8388455

View File

@ -1111,7 +1111,7 @@ void tst_QGraphicsGridLayout::removeItem()
QCOMPARE(l->count(), 4);
QTest::ignoreMessage(QtWarningMsg, QString::fromLatin1("QGraphicsGridLayout::removeAt: invalid index -1").toLatin1().constData());
l->removeItem(new QGraphicsWidget);
l->removeItem(new QGraphicsWidget(widget));
QCOMPARE(l->count(), 4);
}