scripting: Guard against the case where a window is destroyed after changing visibility
If the visiblityChanged signal is emitted and then the window is immediately destroyed, the slot will still be executed because the connection has type of Qt::QueuedConnection.
This commit is contained in:
parent
23129c09ce
commit
adac3b8646
1 changed files with 4 additions and 3 deletions
|
@ -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<QQuickWindow> guard = window;
|
||||
connect(window, &QWindow::visibilityChanged, this, [guard](QWindow::Visibility visibility) {
|
||||
if (guard && visibility == QWindow::Hidden) {
|
||||
guard->destroy();
|
||||
}
|
||||
}, Qt::QueuedConnection);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue