diff --git a/src/plugins/platforms/wayland/qwaylandwindow.cpp b/src/plugins/platforms/wayland/qwaylandwindow.cpp index 9a7b7f09eb0..d04e76b503d 100644 --- a/src/plugins/platforms/wayland/qwaylandwindow.cpp +++ b/src/plugins/platforms/wayland/qwaylandwindow.cpp @@ -54,6 +54,7 @@ #include "qwaylandwindowmanagerintegration_p.h" #include +#include #include #include @@ -245,9 +246,14 @@ void QWaylandWindow::setVisible(bool visible) // QWaylandShmBackingStore::beginPaint(). } else { QWindowSystemInterface::handleExposeEvent(window(), QRegion()); + // when flushing the event queue, it could contain a close event, in which + // case 'this' will be deleted. When that happens, we must abort right away. + QPointer deleteGuard(this); QWindowSystemInterface::flushWindowSystemEvents(); - attach(static_cast(0), 0, 0); - commit(); + if (!deleteGuard.isNull()) { + attach(static_cast(0), 0, 0); + commit(); + } } }