From 1ebb55f951f9ce6032661a49ead449a5ceb26364 Mon Sep 17 00:00:00 2001 From: Peter L Jones Date: Sat, 12 Aug 2023 14:54:42 +0100 Subject: [PATCH] Fixes: #2395 - settings lost on GUI state change --- src/settings.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/settings.h b/src/settings.h index 5ae3efb181..3fe2b72a19 100644 --- a/src/settings.h +++ b/src/settings.h @@ -29,6 +29,7 @@ #include #include #ifndef HEADLESS +# include # include #endif #include "global.h" @@ -50,6 +51,31 @@ class CSettings : public QObject strFileName ( "" ) { QObject::connect ( QCoreApplication::instance(), &QCoreApplication::aboutToQuit, this, &CSettings::OnAboutToQuit ); +#ifndef HEADLESS + + // The Jamulus App will be created as either a QCoreApplication or QApplication (a subclass of QGuiApplication). + // State signals are only delivered to QGuiApplications, so we determine here whether we instantiated the GUI. + const QGuiApplication* pGApp = dynamic_cast ( QCoreApplication::instance() ); + + if ( pGApp != nullptr ) + { +# ifndef QT_NO_SESSIONMANAGER + QObject::connect ( + pGApp, + &QGuiApplication::saveStateRequest, + this, + [=] ( QSessionManager& ) { Save(); }, + Qt::DirectConnection ); + +# endif + QObject::connect ( pGApp, &QGuiApplication::applicationStateChanged, this, [=] ( Qt::ApplicationState state ) { + if ( Qt::ApplicationActive != state ) + { + Save(); + } + } ); + } +#endif } void Load ( const QList& CommandLineOptions );