Skip to content

Commit

Permalink
Fixes: #2395 - settings lost on GUI state change
Browse files Browse the repository at this point in the history
  • Loading branch information
pljones committed Mar 26, 2024
1 parent 2c19b5e commit 9f876e0
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <QSettings>
#include <QDir>
#ifndef HEADLESS
# include <QApplication>
# include <QMessageBox>
#endif
#include "global.h"
Expand All @@ -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<const QGuiApplication*> ( 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<QString>& CommandLineOptions );
Expand Down

0 comments on commit 9f876e0

Please sign in to comment.