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.9 6.6 6.5 5.15
Change-Id: Ic110ea7b93aa0023c0903c776a30dc5c377ce0c5
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
This commit is contained in:
Marc Mutz 2025-04-03 13:58:55 +02:00
parent b37f84ba41
commit 4d0f979610

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