QWidgetWindow: check if receiver is deleted after event delivery

When a popup is active, we set the receiver of mouse events to
be the active popup widget. But when we send a mouse event to
the popup, the receiver might start a new QEventLoop (e.g by
executing a new dialog). And in the meantime, the popup will
be destroyed. This will cause a crash in the line after the
event delivery (where we sat "qt_last_mouse_receiver = receiver"),
since at that point, "receiver" would be a dangling pointer.

This patch will use a QPointer instead of a raw pointer to
store "receiver", to ensure that it's set to null for
such cases.

Fixes: QTBUG-71062
Change-Id: Ie017cfa97370513ecfdd62c056fcb0e6c991f9f6
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
This commit is contained in:
Richard Moe Gustavsen 2018-11-06 13:38:09 +01:00
parent cfbb0d2b40
commit a545b85bdd

View File

@ -521,7 +521,7 @@ void QWidgetWindow::handleMouseEvent(QMouseEvent *event)
if (activePopupWidget->isEnabled()) {
// deliver event
qt_replay_popup_mouse_event = false;
QWidget *receiver = activePopupWidget;
QPointer<QWidget> receiver = activePopupWidget;
QPoint widgetPos = mapped;
if (qt_button_down)
receiver = qt_button_down;