From 794140fb86b470821e3a298a0ba9c8dbbee202b9 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sat, 17 Nov 2018 14:58:15 +0100 Subject: QGraphicsProxyWidget: Don't crash within setWidget() when a child proxy has no assigned widget QGraphicsProxyWidget::setWidget() is checking if the newly assigned widget is already assigned to a child proxy widget without checking if the child has a widget assigned at all which lead to a nullptr reference if it is not the case. Therefore check if the assigned widget is a valid pointer. Fixes: QTBUG-15442 Change-Id: I006877f99895ca01975bdcad071cfcf90bea22ad Reviewed-by: Friedemann Kleint Reviewed-by: Richard Moe Gustavsen --- src/widgets/graphicsview/qgraphicsproxywidget.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/widgets/graphicsview') diff --git a/src/widgets/graphicsview/qgraphicsproxywidget.cpp b/src/widgets/graphicsview/qgraphicsproxywidget.cpp index 177dbc4871..513cf9d361 100644 --- a/src/widgets/graphicsview/qgraphicsproxywidget.cpp +++ b/src/widgets/graphicsview/qgraphicsproxywidget.cpp @@ -607,20 +607,20 @@ void QGraphicsProxyWidgetPrivate::setWidget_helper(QWidget *newWidget, bool auto for (QGraphicsItem *child : childItems) { if (child->d_ptr->isProxyWidget()) { QGraphicsProxyWidget *childProxy = static_cast(child); - QWidget * parent = childProxy->widget(); - while (parent->parentWidget() != 0) { + QWidget *parent = childProxy->widget(); + while (parent && parent->parentWidget()) { if (parent == widget) break; parent = parent->parentWidget(); } if (!childProxy->widget() || parent != widget) continue; - childProxy->setWidget(0); + childProxy->setWidget(nullptr); delete childProxy; } } - widget = 0; + widget = nullptr; #ifndef QT_NO_CURSOR q->unsetCursor(); #endif -- cgit v1.2.3