diff --git a/src/scripting/scripting.cpp b/src/scripting/scripting.cpp index 27e842bdc0..6870121c9c 100644 --- a/src/scripting/scripting.cpp +++ b/src/scripting/scripting.cpp @@ -570,9 +570,10 @@ QVariant KWin::JSEngineGlobalMethodsWrapper::readConfig(const QString &key, QVar void KWin::JSEngineGlobalMethodsWrapper::registerWindow(QQuickWindow *window) { - connect(window, &QWindow::visibilityChanged, this, [window](QWindow::Visibility visibility) { - if (visibility == QWindow::Hidden) { - window->destroy(); + QPointer guard = window; + connect(window, &QWindow::visibilityChanged, this, [guard](QWindow::Visibility visibility) { + if (guard && visibility == QWindow::Hidden) { + guard->destroy(); } }, Qt::QueuedConnection); }