From 257eaa6408aeb965ceaeee2bb61dfd65e65e3e28 Mon Sep 17 00:00:00 2001 From: Ivan Solovev Date: Fri, 10 Mar 2023 16:40:20 +0100 Subject: [PATCH] Imagescaling example: fix memory leaks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * The DownloadDialog was never destroyed properly. Pass 'this' to its constructor to fix it. * When re-creating an image grid layout, properly clean up old image labels in Images::initLayout() Task-number: QTBUG-103514 Change-Id: Ief52774002632d4ad3a6cca85bb0c0aa1a1d4bc0 Reviewed-by: MÃ¥rten Nordheim Reviewed-by: Jarek Kobus (cherry picked from commit 0ac234f9e256949cbacb77f94d39fff90caba7b4) Reviewed-by: Qt Cherry-pick Bot --- examples/qtconcurrent/imagescaling/imagescaling.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/qtconcurrent/imagescaling/imagescaling.cpp b/examples/qtconcurrent/imagescaling/imagescaling.cpp index fca9291e8b7..4b19012c043 100644 --- a/examples/qtconcurrent/imagescaling/imagescaling.cpp +++ b/examples/qtconcurrent/imagescaling/imagescaling.cpp @@ -9,7 +9,7 @@ #include -Images::Images(QWidget *parent) : QWidget(parent), downloadDialog(new DownloadDialog()) +Images::Images(QWidget *parent) : QWidget(parent), downloadDialog(new DownloadDialog(this)) { setWindowTitle(tr("Image downloading and scaling example")); resize(800, 600); @@ -191,6 +191,7 @@ void Images::initLayout(qsizetype count) QLayoutItem *child; while ((child = imagesLayout->takeAt(0)) != nullptr) { child->widget()->setParent(nullptr); + delete child->widget(); delete child; } labels.clear();