diff --git a/mainwindow.cpp b/mainwindow.cpp
index ca6d7202d2dd844b3af4c5a639803f779991cce2..3bb7fed7df1d92c6113795888ede110e9f3265de 100644
--- a/mainwindow.cpp
+++ b/mainwindow.cpp
@@ -150,10 +150,8 @@ MainWindow::MainWindow(QWidget* parent) :
 
     lastScr_ = startScreen;
 
-    connect(windowHandle(), &QWindow::activeChanged,
+    activeChangedConnection_ = connect(windowHandle(), &QWindow::activeChanged,
         [this]() {
-            if (!qApp)
-                return;
             auto screenNumber = qApp->desktop()->screenNumber();
             QScreen* screen = qApp->screens().at(screenNumber);
             windowHandle()->setScreen(nullptr);
@@ -293,6 +291,7 @@ MainWindow::closeEvent(QCloseEvent* event)
         settings.setValue(SettingsKey::windowState, saveState());
     }
     this->disconnect(screenChangedConnection_);
+    this->disconnect(activeChangedConnection_);
     LRCInstance::reset();
     QMainWindow::closeEvent(event);
 }
diff --git a/mainwindow.h b/mainwindow.h
index 02e6138d05061f6374c3f58d88badcc41ef443d6..e2bce37a6844daaed26bea0d597453dfaddff591 100644
--- a/mainwindow.h
+++ b/mainwindow.h
@@ -85,4 +85,5 @@ private:
     Ui::MainWindow* ui;
     QNetworkConfigurationManager netManager_;
     QMetaObject::Connection screenChangedConnection_;
+    QMetaObject::Connection activeChangedConnection_;
 };