# Save parameters as config object

**URL:** <https://discourse.slicer.org/t/save-parameters-as-config-object/21103>\
**Category:** Development\
**Tags:** scripted\
**Created:** [December 17, 2021, 1:36am UTC](https://discourse.slicer.org/t/save-parameters-as-config-object/21103 "2021-12-17T01:36:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Karthik](https://avatars.discourse-cdn.com/v4/letter/k/9fc348/32.png) [@Karthik](https://discourse.slicer.org/u/Karthik)\
**Post date:** [December 17, 2021, 1:36am UTC](https://discourse.slicer.org/t/save-parameters-as-config-object/21103/1 "2021-12-17T01:36:59Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Alex\_Vergara](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/alex_vergara/32/15205_2.png) [@Alex\_Vergara](https://discourse.slicer.org/u/Alex_Vergara)\
**Post date:** [December 17, 2021, 7:40am UTC](https://discourse.slicer.org/t/save-parameters-as-config-object/21103/2 "2021-12-17T07:40:04Z")

</div>

That is what I did in my module, watch this file [OpenDose3D/Logic/config.py · develop · OpenDose / SlicerOpenDose3D · GitLab](https://gitlab.com/opendose/opendose3d/-/blob/develop/OpenDose3D/Logic/config.py)

---

<div class="post-metadata">

**Author:** ![Mik](https://avatars.discourse-cdn.com/v4/letter/m/958977/32.png) [@Mik](https://discourse.slicer.org/u/Mik)\
**Post date:** [December 17, 2021, 8:44am UTC](https://discourse.slicer.org/t/save-parameters-as-config-object/21103/3 "2021-12-17T08:44:43Z")

</div>

You can use QSettings if module contains Qt. [For example](https://github.com/Slicer/Slicer/blob/master/Modules/Scripted/DICOM/DICOM.py#L81-L83)

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

```

---

<div class="post-metadata">

**Author:** ![Alex\_Vergara](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/alex_vergara/32/15205_2.png) [@Alex\_Vergara](https://discourse.slicer.org/u/Alex_Vergara)\
**Post date:** [December 17, 2021, 4:08pm UTC](https://discourse.slicer.org/t/save-parameters-as-config-object/21103/4 "2021-12-17T16:08:35Z")

</div>

> [@Mik](#):
>
> You can use QSettings if module contains Qt.

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

---

<div class="post-metadata">

**Author:** ![Mik](https://avatars.discourse-cdn.com/v4/letter/m/958977/32.png) [@Mik](https://discourse.slicer.org/u/Mik)\
**Post date:** [December 18, 2021, 4:57am UTC](https://discourse.slicer.org/t/save-parameters-as-config-object/21103/5 "2021-12-18T04:57:07Z")

</div>

> [@Alex\_Vergara](#):
>
> 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](https://github.com/Slicer/Slicer/blob/master/Base/QTApp/qSlicerApplicationHelper.cxx). There are not so many places where config file is stored by default (see Basic usage: [QSettings Class | Qt Core 5.15.16](https://doc.qt.io/qt-5/qsettings.html#basic-usage) and Platform-specific notes: [QSettings Class | Qt Core 5.15.16](https://doc.qt.io/qt-5/qsettings.html#platform-specific-notes) 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`
