Skip to content

Commit 6f28c7c

Browse files
authored
Merge pull request #3144 from pljones/bugfix/2395-save-settings-on-state-change
Android: settings lost on GUI state change
2 parents 2f769f5 + 1ebb55f commit 6f28c7c

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/settings.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <QSettings>
3030
#include <QDir>
3131
#ifndef HEADLESS
32+
# include <QApplication>
3233
# include <QMessageBox>
3334
#endif
3435
#include "global.h"
@@ -50,6 +51,31 @@ class CSettings : public QObject
5051
strFileName ( "" )
5152
{
5253
QObject::connect ( QCoreApplication::instance(), &QCoreApplication::aboutToQuit, this, &CSettings::OnAboutToQuit );
54+
#ifndef HEADLESS
55+
56+
// The Jamulus App will be created as either a QCoreApplication or QApplication (a subclass of QGuiApplication).
57+
// State signals are only delivered to QGuiApplications, so we determine here whether we instantiated the GUI.
58+
const QGuiApplication* pGApp = dynamic_cast<const QGuiApplication*> ( QCoreApplication::instance() );
59+
60+
if ( pGApp != nullptr )
61+
{
62+
# ifndef QT_NO_SESSIONMANAGER
63+
QObject::connect (
64+
pGApp,
65+
&QGuiApplication::saveStateRequest,
66+
this,
67+
[=] ( QSessionManager& ) { Save(); },
68+
Qt::DirectConnection );
69+
70+
# endif
71+
QObject::connect ( pGApp, &QGuiApplication::applicationStateChanged, this, [=] ( Qt::ApplicationState state ) {
72+
if ( Qt::ApplicationActive != state )
73+
{
74+
Save();
75+
}
76+
} );
77+
}
78+
#endif
5379
}
5480

5581
void Load ( const QList<QString>& CommandLineOptions );

0 commit comments

Comments
 (0)