From fe0b29a45c19ad401ab5e4d17bec2e2d3e2c618c Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 4 Apr 2025 08:10:53 +0200 Subject: [PATCH] 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.9 6.8 6.5 5.15 Change-Id: I8d80713f4ff6b1055bc396d855f98bc1873aee3b Reviewed-by: Axel Spoerl --- .../qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/auto/widgets/graphicsview/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp b/tests/auto/widgets/graphicsview/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp index b6f73ed74f3..70a293a8087 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp @@ -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);