Save parameters as config object

Hi.
I have written a scripted module which has some parameters in the form of sliderwidgets. Currently, I am saving these as .cfg file through the code and reading them next time the same module is instantiated. I was wondering if Slicer has a way to save the current state (values) of these parameters which can then be loaded back and the values would be restored. I know that we can save the mrml scene, but I only want to save the parameter values. Is this possible?

That is what I did in my module, watch this file OpenDose3D/Logic/config.py · develop · OpenDose / SlicerOpenDose3D · GitLab

You can use QSettings if module contains Qt. For example

import qt
value = 10.1
settings = qt.QSettings()
# save value
settings.setValue('MyModule/MyValue', value)
...
# load value
newValue = settings.value('MyModule/MyValue')

Isn’t this dangerous? You have no control where the config file is located and you offuscate qt settings with your stuff

User can define a config file name explicitly in constructor, without using Slicer config file.

With empty constructor QSettings uses application defined parameters. There are not so many places where config file is stored by default (see Basic usage: QSettings Class | Qt Core 5.15.7 and Platform-specific notes: QSettings Class | Qt Core 5.15.7 for QSettings).

In my case Slicer config file has groups for different modules: Markups, SubjectHierarchy, VolumeRendering. Linux file name path: /home/user/.config/NA-MIC/Slicer.ini