From 4df5f93018344f6cdc6cd5a08a084b1c61e0c076 Mon Sep 17 00:00:00 2001 From: Zhang Yu Date: Tue, 17 Nov 2020 21:05:39 +0800 Subject: Fix QGraphicsItem crash if click right button of mouse In this case, the 'parent' is QGraphicsTextItem which isn't a object inheriting from QWidget. Converting QGraphicsTextItem to QWidget by static_cast and using it as QWidget leads to crash. Fixes: QTBUG-88309 Pick-to: 5.15 Change-Id: I3c583f43125eb36841848434d1fa9a135b0e9f57 Reviewed-by: Volker Hilsheimer --- src/widgets/widgets/qwidgettextcontrol.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/widgets/widgets') diff --git a/src/widgets/widgets/qwidgettextcontrol.cpp b/src/widgets/widgets/qwidgettextcontrol.cpp index 024713fad3..9fe6e3e1e3 100644 --- a/src/widgets/widgets/qwidgettextcontrol.cpp +++ b/src/widgets/widgets/qwidgettextcontrol.cpp @@ -1943,8 +1943,12 @@ void QWidgetTextControlPrivate::contextMenuEvent(const QPoint &screenPos, const if (!menu) return; menu->setAttribute(Qt::WA_DeleteOnClose); - if (auto *window = static_cast(parent)->window()->windowHandle()) - QMenuPrivate::get(menu)->topData()->initialScreen = window->screen(); + + if (auto *widget = qobject_cast(parent)) { + if (auto *window = widget->window()->windowHandle()) + QMenuPrivate::get(menu)->topData()->initialScreen = window->screen(); + } + menu->popup(screenPos); #endif } -- cgit v1.2.3