Save Programm Settings internally + how to organize with folders?
-
@StudentScripter hi,
QSettings is a good way to go. If you want to use JSON with it, you can leverage registerFormat.
-
Settings need to be changed in a separate file (or the registry on Windows). Qt does not provide a way to change the executable itself. Files inside qrc are read-only (even if they are separate files on disk, i.e. qrc files read at runtime).
Every operating system has a default way of storing settings. Just use QSettings (with your "company" and application name) and it will store it in the right place. You can add default values for your settings with QSettings so that you can create the initial settings file.
-
@SimonSchroeder But doesn't create qsetting endless registry entrys while testing? How to get rid of them?
-
@StudentScripter you can specify custom path where the settings will be saved (to a file, not registry). Then it is easy, when you need a "clean slate" you just delete the file.
-
Something like this? And than remove this path at the end when my development is finished to save it in the users registry?
QString filePath = "/path/to/your/settings.ini"; QSettings settings(filePath, QSettings::IniFormat);
-
@StudentScripter Yes you can do that. Or you can just go into the Registry at "your "company" and application name " and delete that.
-
@StudentScripter said in Save Programm Settings internally + how to organize with folders?:
And than remove this path at the end when my development is finished to save it in the users registry?
Like this, or you stick to the
.ini
file mode and just delete it in order to be re-created in a clean state by your program.@JonB said in Save Programm Settings internally + how to organize with folders?:
Or you can just go into the Registry at "your "company" and application name " and delete that.
If only every software dev would do this... :)
That's why 99% of all Windows users have a bloated registry... because most programs don't delete all its entries even when you uninstall them.
Some leave it up to you while uninstalling to check/uncheck an option to keep or delete config. and "user data" in the registry, which is fine :) -
@StudentScripter said in Save Programm Settings internally + how to organize with folders?:
I don't want the endusers registry to get bloated over time.
You know what you write to registry. Every
QSetting
key is stored the way you set it up.
Unless you write (possibly) endless arrays to registry, the amount of keys should stay the same.
You have your "organisation" and your group, so you know where to find your keys.
How you delete them completely is mentioned here: -
@StudentScripter said in Save Programm Settings internally + how to organize with folders?:
@JonB How i the behaviour with qSetting when i allow it to do registry entrys. I don't want the endusers registry to get bloated over time.
I don't understand the question. But what I can say is: when you go to production/have end users under Windows they will expect you store settings in the Registry rather than
.ini
files (which you won't much know where to put anyway). So it's all very well for you to decide that in your development environment you (seem to) want to use.ini
file so you can delete it, but I don;t think you should do that in production/release and that means you will have different paths of code.QSettings
is only saving downward from one registry key (as mentioned earlier) so it's not too "polluting", and you are using the same company/application name the whole time so that's it. As for "bloated", the registry will likely be GB rather than MB big, so a few entries from you won't make much difference. Unless you are intending to save megabytes of information, which I doubt!I don't know how you install your application to end users, but most Windows application installers delete application's registry key on uninstall.
-
-
@StudentScripter said in Save Programm Settings internally + how to organize with folders?:
QString filePath = "/path/to/your/settings.ini";
If you want to use an ini file, please use QStandardPath with ConfigLocation and don't invent your own place where to put the ini file.