QStackedLayout: fix a memory leak

A layout takes ownership of the QLayoutItem passed to addItem.

Change-Id: Iea3c64453f3cbf4f1b5660e505c1a35dca537833
Pick-to: 6.0 5.15 5.12
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
Giuseppe D'Angelo 2020-11-22 16:02:50 +01:00
parent 910203afb4
commit 1fcc882d7c

View File

@ -44,6 +44,8 @@
#include "private/qwidget_p.h"
#include "private/qlayoutengine_p.h"
#include <memory>
QT_BEGIN_NAMESPACE
class QStackedLayoutPrivate : public QLayoutPrivate
@ -421,13 +423,13 @@ int QStackedLayout::count() const
*/
void QStackedLayout::addItem(QLayoutItem *item)
{
std::unique_ptr<QLayoutItem> guard(item);
QWidget *widget = item->widget();
if (Q_UNLIKELY(!widget)) {
qWarning("QStackedLayout::addItem: Only widgets can be added");
return;
}
addWidget(widget);
delete item;
}
/*!