tst_QGraphicsWidget: fix memleak in shortcutsDeletion()

The QGraphicsWidget didn't have a parent, and wasn't deleted by the
test function, so it leaked.

To fix, hold it in unique_ptr. While we're at it, and so that it
doesn't look too out of place, also hold the other parent-less
QGraphicsWidget in a unique_ptr.

The action, OTOH, has a parent, so we don't need to change something
there.

Amends the start of the public history.

Pick-to: 6.8 6.5 5.15
Change-Id: I0597b7ecd293ac54981df9e276c38c385ac811c7
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
(cherry picked from commit 92c1413c087c5435858f10c0e0c878bc25211b8f)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2025-03-28 09:40:44 +01:00 committed by Qt Cherry-pick Bot
parent 604a76c8b3
commit c57d487d9b

View File

@ -2567,16 +2567,16 @@ void tst_QGraphicsWidget::windowFlags()
void tst_QGraphicsWidget::shortcutsDeletion()
{
QGraphicsWidget *widget = new QGraphicsWidget;
QGraphicsWidget *widget2 = new QGraphicsWidget;
auto widget = std::make_unique<QGraphicsWidget>();
const auto widget2 = std::make_unique<QGraphicsWidget>();
widget->setMinimumSize(40, 40);
QWidgetAction *del = new QWidgetAction(widget);
QWidgetAction *del = new QWidgetAction(widget.get());
del->setIcon(QIcon("edit-delete"));
del->setShortcut(Qt::Key_Delete);
del->setShortcutContext(Qt::WidgetShortcut);
widget2->addAction(del);
widget2->addAction(del);
delete widget;
widget.reset();
}
class MessUpPainterWidget : public QGraphicsWidget