Imagescaling example: fix memory leaks

* 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
Pick-to: 6.5 6.5.0
Change-Id: Ief52774002632d4ad3a6cca85bb0c0aa1a1d4bc0
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
Ivan Solovev 2023-03-10 16:40:20 +01:00
parent 441993a9a2
commit 0ac234f9e2

View File

@ -8,7 +8,7 @@
#include <functional>
Images::Images(QWidget *parent) : QWidget(parent), downloadDialog(new DownloadDialog())
Images::Images(QWidget *parent) : QWidget(parent), downloadDialog(new DownloadDialog(this))
{
resize(800, 600);
@ -189,6 +189,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();