tst_QGraphicsGridLayout: fix memleaks in spanningItem2x3()

The test function creates a bunch of QGraphicsWidgets without parents,
and adding them to the QGraphicsGridLayout doesn't make them owned by
it. Besides, the layout was without a parent itself, so all these
objects were leaked.

To fix, give the layout a stack-allocated QGraphicsWidget parent. Now,
the layout will reparent the widgets added to it to its own parent
widget, which will delete layout and child widgets when it itself is
deleted on all exists from the test function.

Amends the start of the public history.

Pick-to: 6.8 6.5 5.15
Change-Id: I8d80713f4ff6b1055bc396d855f98bc1873aee3b
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
(cherry picked from commit fe0b29a45c19ad401ab5e4d17bec2e2d3e2c618c)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2025-04-04 08:10:53 +02:00 committed by Qt Cherry-pick Bot
parent 389dab064e
commit 9a9530fd08

View File

@ -3231,7 +3231,12 @@ void tst_QGraphicsGridLayout::spanningItem2x3()
QFETCH(bool, w3_fixed);
QFETCH(bool, w4_fixed);
QFETCH(bool, w5_fixed);
QGraphicsGridLayout *layout = new QGraphicsGridLayout;
QGraphicsWidget parent;
parent.setLayout(layout);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);