Be more graceful when objects die by the time the dnd loop exits

The main issue fixed in 7f23dd963536eb8123ee4c5c22bf43b6f866d008 can
manifest in another form on platforms where QBasicDrag is used (xcb).

Make sure that we recognize if an object (e.g. a QWidgetWindow) is
destroyed by the time the nested event loop exits.

Task-number: QTBUG-104596
Change-Id: Ib82dd8230cb6f13d804bd992234b2a3ce85a7061
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
(cherry picked from commit 742ae9ea1cadbb438e2d02bb58ae900c676dc41c)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Laszlo Agocs 2022-07-01 15:20:08 +02:00 committed by Qt Cherry-pick Bot
parent fe6f7de8ce
commit c514812aaf

View File

@ -124,6 +124,7 @@ bool QBasicDrag::eventFilter(QObject *o, QEvent *e)
} }
case QEvent::MouseButtonRelease: case QEvent::MouseButtonRelease:
{ {
QPointer<QObject> objGuard(o);
disableEventFilter(); disableEventFilter();
if (canDrop()) { if (canDrop()) {
QPoint nativePosition = getNativeMousePos(e, m_drag_icon_window); QPoint nativePosition = getNativeMousePos(e, m_drag_icon_window);
@ -133,6 +134,8 @@ bool QBasicDrag::eventFilter(QObject *o, QEvent *e)
cancel(); cancel();
} }
exitDndEventLoop(); exitDndEventLoop();
if (!objGuard)
return true;
// If a QShapedPixmapWindow (drag feedback) is being dragged along, the // If a QShapedPixmapWindow (drag feedback) is being dragged along, the
// mouse event's localPos() will be relative to that, which is useless. // mouse event's localPos() will be relative to that, which is useless.