tst_QGraphicsGridLayout: fix memory leaks in rowCount()

The populateLayoutWithSpansAndHoles() function adds parent-less
QGraphicsWidgets (RectItems) to the layout. If the layout had a
graphics-widget parent, it would reparent the items added to it onto
the parent. But it didn't, so it didn't.

Therefore, the last part of the test function (as denoted by the
re-creation of `layout`) leaked a lot of items, including `layout`.

To fix, give the layout the existing graphics-widget parent. Then the
layout itself isn't leaked anymore, either.

Amends the start of the public history.

Pick-to: 6.9 6.8 6.5 5.15
Change-Id: I063c0e3336d943a35592fa62a5d16cbddb6b920e
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
This commit is contained in:
Marc Mutz 2025-04-02 21:08:41 +02:00
parent 5a559758d1
commit b9836518a3

View File

@ -1211,6 +1211,7 @@ void tst_QGraphicsGridLayout::rowCount()
// with spans and holes...
widget->setLayout(0);
layout = new QGraphicsGridLayout();
widget->setLayout(layout);
populateLayoutWithSpansAndHoles(layout, hasHeightForWidth);
QCOMPARE(layout->rowCount(), 2);
QCOMPARE(layout->columnCount(), 3);