Settings.h, sailjail default locations

Believing the default paths to be automagcially available when declaring Sailjail org/name, I hadn’t done anything to explicitly declare them in machines vs. machines main. This seems to be in error.

The machines-vs-machines-sfos.cpp includes:

QObject* createSettings(QQmlEngine *engine, QJSEngine *jsEngine)
{
    return new Settings();
}
qmlRegisterSingletonType<Settings>("harbour.machines.vs.machines.sfos.Machines", 1, 0, "SettingsBackend", createSettings);

The sailjail has org set (de.poetaster), but the settings don’t seem to be stored there but wind up in the ‘old’ default location, .config/harbour-machines-vs-machines-sfos/

I’m not sure if this is a bug. Perhaps setting

app->setOrganizationDomain("de.poetaster");

is sufficient. But I’m not sure?

To answer my last question, no.

app->setOrganizationName(“de.poetaster”); // needed for Sailjail
app->setApplicationName(“harbour-machines-vs-machines-sfos”);

qmlRegisterSingletonType(“harbour.machines.vs.machines.sfos.Machines”, 1, 0, “SettingsBackend”, createSettings);

Is not sufficient. Looks like the QSettings::setPath may be needed.

For that reason I decided to create the paths myself. For example in File Browser:

QString newConfigDir = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation);
QString configFile = QCoreApplication::applicationName() + ".conf";
QSettings global(newConfigDir + "/" + configFile, QSettings::IniFormat);
m_globalConfigPath = global.fileName();

(Setting organization name and application name is required here, of course.)

Yeah, I tried that :slight_smile: I finally found it. It was hardcoded in the Settings class header file:

#define SETTINGS(group) QSettings settings("harbour-machines-vs-machines-sfos", "harbour-machines-vs-machines-sfos"); settings.beginGroup(group)

The main is very minimal, which has a certain charm but meant having to dig to find out why the defaults were being overridden. I was looking in the wrong place :slight_smile:

For reference the main was:

   qmlRegisterType<Engine>("harbour.machines.vs.machines.sfos.Machines", 1, 0, "Engine");
   qmlRegisterUncreatableType<LevelPacks>("harbour.machines.vs.machines.sfos.Machines", 1, 0, "LevelPacks", "Can't create this in QML. Get it from Engine.");

   qmlRegisterType<BoardProxyModel>("harbour.machines.vs.machines.sfos.Machines", 1, 0, "BoardProxyModel");
   qmlRegisterSingletonType<Settings>("harbour.machines.vs.machines.sfos.Machines", 1, 0, "SettingsBackend", createSettings);
   return SailfishApp::main(argc, argv);

and

Not really a good idea if you want to re-use the code, but it does work :slight_smile:

Sigh:

This, instantiating with orgname and appname:

#define SETTINGS(group) QSettings settings("de.poetaster", "harbour-machines-vs-machines-sfos"); settings.beginGroup(group)

does not work. this, instantiating with path:

#define SETTINGS(group) QSettings settings("de.poetaster/harbour-machines-vs-machines-sfos/settings"); settings.beginGroup(group)

does.

Strange. But @ichthyosaurus your method works anyway :slight_smile:

 app->setApplicationName("harbour-machines-vs-machines-sfos");           
 app->setOrganizationDomain("de.poetaster");
 app->setOrganizationName("de.poetaster"); 

Followed by

QString newConfigDir = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation);
QString configFile = QCoreApplication::applicationName() + ".conf";
QSettings global(newConfigDir + "/" + configFile, QSettings::IniFormat);

using the original

qmlRegisterSingletonType<Settings>("harbour.machines.vs.machines.sfos.Machines", 1, 0, "SettingsBackend", createSettings);

Works as expected.

1 Like

Ok. This is wrong. Running under the sdk and from the launcher are different things.

EDIT: What it boils down to is that if you have the Sailjail conf in .desktop as I did AND the settings object initializes with a define as in the case of machines vs. machines, if won’t work.

Running from the sdk you will appear to suceed, as I did with the post from 8 hours ago. But it isn’t so.

I’ve modified the define and adjusted the .desktop to ‘fix it’ but basically the way that settings is implmented in machines vs. machines doesn’t work well in the sailjail context.