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.