diff options
author | Jarek Kobus <jaroslaw.kobus@qt.io> | 2022-07-27 08:28:16 +0200 |
---|---|---|
committer | Jarek Kobus <jaroslaw.kobus@qt.io> | 2022-07-27 12:45:00 +0000 |
commit | 94310efa060f096e48e6627ccd2dc6f4360bcd71 (patch) | |
tree | 577ed6595751d105a47778259010ed41981e98cc | |
parent | f9ae7c2bc668cb94df975dfea0ec3ce08993b733 (diff) | |
download | qt-creator-94310efa060f096e48e6627ccd2dc6f4360bcd71.tar.gz |
GlobalFileChangeBlocker: Don't install event filter on qApp
Connect to applicationStateChanged() signal instead.
Change-Id: I95ccabd06233902400bda0c01ea89b1c7cdf0e92
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
-rw-r--r-- | src/libs/utils/globalfilechangeblocker.cpp | 20 | ||||
-rw-r--r-- | src/libs/utils/globalfilechangeblocker.h | 3 |
2 files changed, 8 insertions, 15 deletions
diff --git a/src/libs/utils/globalfilechangeblocker.cpp b/src/libs/utils/globalfilechangeblocker.cpp index 060e0f210d..01f5709d0b 100644 --- a/src/libs/utils/globalfilechangeblocker.cpp +++ b/src/libs/utils/globalfilechangeblocker.cpp @@ -26,14 +26,15 @@ #include "globalfilechangeblocker.h" #include "qtcassert.h" -#include <QApplication> +#include <QGuiApplication> namespace Utils { GlobalFileChangeBlocker::GlobalFileChangeBlocker() { - m_blockedState = QApplication::applicationState() != Qt::ApplicationActive; - qApp->installEventFilter(this); + m_blockedState = QGuiApplication::applicationState() != Qt::ApplicationActive; + connect(qApp, &QGuiApplication::applicationStateChanged, + this, &GlobalFileChangeBlocker::applicationStateChanged); } GlobalFileChangeBlocker *GlobalFileChangeBlocker::instance() @@ -48,19 +49,12 @@ void GlobalFileChangeBlocker::forceBlocked(bool blocked) ++m_forceBlocked; else if (QTC_GUARD(m_forceBlocked > 0)) --m_forceBlocked; - emitIfChanged(); + applicationStateChanged(QGuiApplication::applicationState()); } -bool GlobalFileChangeBlocker::eventFilter(QObject *obj, QEvent *e) +void GlobalFileChangeBlocker::applicationStateChanged(Qt::ApplicationState state) { - if (obj == qApp && e->type() == QEvent::ApplicationStateChange) - emitIfChanged(); - return false; -} - -void GlobalFileChangeBlocker::emitIfChanged() -{ - const bool blocked = m_forceBlocked || (QApplication::applicationState() != Qt::ApplicationActive); + const bool blocked = m_forceBlocked || (state != Qt::ApplicationActive); if (blocked != m_blockedState) { emit stateChanged(blocked); m_blockedState = blocked; diff --git a/src/libs/utils/globalfilechangeblocker.h b/src/libs/utils/globalfilechangeblocker.h index 0f36dfce92..9d683797ce 100644 --- a/src/libs/utils/globalfilechangeblocker.h +++ b/src/libs/utils/globalfilechangeblocker.h @@ -45,8 +45,7 @@ signals: private: GlobalFileChangeBlocker(); - bool eventFilter(QObject *obj, QEvent *e) override; - void emitIfChanged(); + void applicationStateChanged(Qt::ApplicationState state); int m_forceBlocked = 0; bool m_blockedState = false; |