diff --git a/src/widgets/kernel/qstackedlayout.cpp b/src/widgets/kernel/qstackedlayout.cpp index f87fe96cc0..2f3d6f39cb 100644 --- a/src/widgets/kernel/qstackedlayout.cpp +++ b/src/widgets/kernel/qstackedlayout.cpp @@ -44,6 +44,8 @@ #include "private/qwidget_p.h" #include "private/qlayoutengine_p.h" +#include + QT_BEGIN_NAMESPACE class QStackedLayoutPrivate : public QLayoutPrivate @@ -421,13 +423,13 @@ int QStackedLayout::count() const */ void QStackedLayout::addItem(QLayoutItem *item) { + std::unique_ptr guard(item); QWidget *widget = item->widget(); if (Q_UNLIKELY(!widget)) { qWarning("QStackedLayout::addItem: Only widgets can be added"); return; } addWidget(widget); - delete item; } /*!