diff options
author | Zhang Yu <zhangyub@uniontech.com> | 2020-11-17 21:05:39 +0800 |
---|---|---|
committer | Zhang Yu <zhangyub@uniontech.com> | 2020-11-18 05:56:27 +0800 |
commit | 4df5f93018344f6cdc6cd5a08a084b1c61e0c076 (patch) | |
tree | 019f7d57ab22c6ec9de16084d5b88d34097db4ae | |
parent | 34304e3100883187ca658b8c983af21549496b43 (diff) |
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 <volker.hilsheimer@qt.io>
-rw-r--r-- | src/widgets/widgets/qwidgettextcontrol.cpp | 8 |
1 files changed, 6 insertions, 2 deletions
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<QWidget *>(parent)->window()->windowHandle()) - QMenuPrivate::get(menu)->topData()->initialScreen = window->screen(); + + if (auto *widget = qobject_cast<QWidget *>(parent)) { + if (auto *window = widget->window()->windowHandle()) + QMenuPrivate::get(menu)->topData()->initialScreen = window->screen(); + } + menu->popup(screenPos); #endif } |