Darkmode. Fix crash on exit.
authoralex-z <blackslayer4@gmail.com>
Wed, 30 Mar 2022 15:07:49 +0000 (18:07 +0300)
committerMatthieu Gallien (Rebase PR Action) <matthieu_gallien@yahoo.fr>
Fri, 1 Apr 2022 08:41:35 +0000 (08:41 +0000)
Signed-off-by: alex-z <blackslayer4@gmail.com>
src/libsync/theme.cpp
src/libsync/theme.h

index 34bea7287003865028c590f24c2ada704a6dde00..eb2268ca2f567654f60e318b77bc678d2d4d8fcb 100644 (file)
@@ -904,12 +904,11 @@ QColor Theme::errorBoxBorderColor() const
 
 void Theme::connectToPaletteSignal()
 {
-    if(!_guiAppInstance) {
-        const auto ptr = qobject_cast<QGuiApplication *>(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 *>(QGuiApplication::instance())) {
+            connect(ptr, &QGuiApplication::paletteChanged, this, &Theme::systemPaletteChanged);
+            connect(ptr, &QGuiApplication::paletteChanged, this, &Theme::darkModeChanged);
+            _paletteSignalsConnected = true;
         }
     }
 }
index df9303b2362a4863ae77742e1d2ad252bbbcf560..180efbec2673fceeddf0cb34aa1d98647364ed9c 100644 (file)
@@ -627,7 +627,7 @@ private:
 
     static Theme *_instance;
     bool _mono = false;
-    QScopedPointer<QGuiApplication> _guiAppInstance;
+    bool _paletteSignalsConnected = false;
 
 #ifndef TOKEN_AUTH_ONLY
     mutable QHash<QString, QIcon> _iconCache;