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.8 6.5 5.15
Change-Id: I063c0e3336d943a35592fa62a5d16cbddb6b920e
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
(cherry picked from commit b9836518a367a31a48027a5bf81c4973b847b442)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2025-04-02 21:08:41 +02:00 committed by Qt Cherry-pick Bot
parent 690243d333
commit 3295e7d52b

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