From b34f639fff1d65d7379633994d7bb2c299c38b7a Mon Sep 17 00:00:00 2001 From: alex-z Date: Wed, 30 Mar 2022 18:07:49 +0300 Subject: [PATCH] Darkmode. Fix crash on exit. Signed-off-by: alex-z --- src/libsync/theme.cpp | 11 +++++------ src/libsync/theme.h | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/libsync/theme.cpp b/src/libsync/theme.cpp index 34bea7287..eb2268ca2 100644 --- a/src/libsync/theme.cpp +++ b/src/libsync/theme.cpp @@ -904,12 +904,11 @@ QColor Theme::errorBoxBorderColor() const void Theme::connectToPaletteSignal() { - if(!_guiAppInstance) { - const auto ptr = qobject_cast(QGuiApplication::instance()); - if(ptr) { - _guiAppInstance.reset(ptr); - connect(_guiAppInstance.data(), &QGuiApplication::paletteChanged, this, &Theme::systemPaletteChanged); - connect(_guiAppInstance.data(), &QGuiApplication::paletteChanged, this, &Theme::darkModeChanged); + if (!_paletteSignalsConnected) { + if (const auto ptr = qobject_cast(QGuiApplication::instance())) { + connect(ptr, &QGuiApplication::paletteChanged, this, &Theme::systemPaletteChanged); + connect(ptr, &QGuiApplication::paletteChanged, this, &Theme::darkModeChanged); + _paletteSignalsConnected = true; } } } diff --git a/src/libsync/theme.h b/src/libsync/theme.h index df9303b23..180efbec2 100644 --- a/src/libsync/theme.h +++ b/src/libsync/theme.h @@ -627,7 +627,7 @@ private: static Theme *_instance; bool _mono = false; - QScopedPointer _guiAppInstance; + bool _paletteSignalsConnected = false; #ifndef TOKEN_AUTH_ONLY mutable QHash _iconCache; -- 2.30.2