Modify value in `SlicerLauncherSettings.ini` from application


Is it possible to set value to SlicerLauncherSettings.ini from application?
For example:"SLICER_HOME", "/my/path")

will modify SLICER_HOME env var but it doesn’t change the value in SlicerLauncherSettings.ini.

You can access/modify the SlicerLauncherSettings.ini file at multiple levels:

  • as any other text file, using standard file read/write functions
  • as a Qt settings file (QSettings settings(fileName, QSettings::IniFormat);)
  • as a CTK launcher settings ini file, using CTKApLauncherLib’s ctkAppLauncherSettings class
1 Like

Thank you for the response,

First I tried to use ctkAppLauncherSettings as it is done in qSlicerCoreApplication but then I understood that ctkAppLauncherSettings doesn’t privide API to overwrite values in file. To do that I would need to work with settings as with usual textual file.

I decided to use userSettings (QSettings class) for now:

QSettings* settings = app->userSettings();
settings->setValue("MyKey", "FALSE");

By the way I don’t know should this work or not but it doesn’t:

settings=qt.QSettings(, 1)  # 1 is QSettings::IniFormat I could not find this enum in python

I expected that settings retrieves information from .ini file and I could work with it as with QSettings.

But settings.allKeys() returns empty list.

And settings.fileName() shows

While returns

As you can see settings.fileName() adds /1.conf at the end.
Am I misunderstanding something?

As I understand there is a constructor QSettings(const QString & fileName , QSettings::Format format , QObject * parent = nullptr) but it works somehow strange

It works for me perfectly if I use the proper Qt constant:

>>> settings=qt.QSettings(, qt.QSettings.IniFormat)
>>> settings.allKeys()
('Application/arguments', 'Application/name', 'Application/organizationDomain', 'Application/organizationName', 'Application/path', 'Application/revision', 'Environment/additionalPathVariables', 'EnvironmentVariables/ITK_AUTOLOAD_PATH', 'EnvironmentVariables/PIP_REQUIRE_VIRTUALENV', 'EnvironmentVariables/PYTHONHOME', 'EnvironmentVariables/PYTHONNOUSERSITE', ...
1 Like

Thank you very much!

Your approach works
I didn’t know that there might be a difference between passing the value 1 and qt.QSettings.IniFormat.