Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Optimal way to access QSettings



  • Hello,
    I have applications where I need to work with user defined values (in QSettings) and my application supports dynamically change settings during runtime (using Settings window).

    I would like to ask you what is optimal way to work with QSettings, I know to options:

    • At start load all settings into one object (struct) and use that object for getting values, if I change settings then I save new settings into QSettings and settings object.
    • Everywhere in application I will always get value from QSettings directly.

  • Lifetime Qt Champion

    Hi,

    Do you have all settings of your app managed in that
    dialog ?

    How is it designed ?



  • Yes all settings are managed in that one settings dialog, on other places across app it is just read-only.


  • Lifetime Qt Champion

    One way is to have your settings widget emitting signals to update your other widgets. That way when you load the settings into the settings widget it will propagate to the others. You'll have one central of truth for your application.

    The other possibility is the other way around, each widget is responsible for managing it's own settings and your dialog allows to change them. Store the latest settings on application end for example.



  • So something like that settings widget will have public struct which will always contain current settings, and other widgets could read from that struct?


Log in to reply