Save Programm Settings internally + how to organize with folders?
-
So two smaller questions qt c++:
-
Whats the best way to store settings for my programm internally? These settings should be read on every startup of the programm so it is essential to store them somehow within the programm. Maybe create a json inside the qrc and read and write there or is there a better way?
-
I have one big project (or atleast it getting quite messy now with continously adding files) how can put them in folders and link them with cmake? Only found information on this with qmake.
Thanks a lot and have a nice day. :)
-
-
@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?:
So two smaller questions qt c++:
- Whats the best way to store settings for my programm internally? These settings should be read on every startup of the programm so it is essential to store them somehow within the programm. Maybe create a json inside the qrc and read and write there or is there a better way?
If you mean this to be read-only and not alterable by users then yes - using QRC is a great solution. Regarding format it is completely up to you - JSON is definitely nice and easy, CBOR gives more performance but is not readable to humans, or you can even use some super simple, custom INI parser.
- I have one big project (or atleast it getting quite messy now with continously adding files) how can put them in folders and link them with cmake? Only found information on this with qmake.
You just put them in folders :-) And update paths in CMakeLists.txt file. That's it.
If you want to make this a bit more modular, you can create (static) libraries out of your files and then link them to the executable.
-
@sierdzio said in Save Programm Settings internally + how to organize with folders?:
Whats the best way to store settings for my programm internally? These settings should be read on every startup of the programm so it is essential to store them somehow within the programm. Maybe create a json inside the qrc and read and write there or is there a better way?
Actually, now that I think about it again - if these are really static, built-in settings we are talking about you can simply create a c++ header file and store your stuff there. No need for QRC as such then.
// settings.h Settings { constexpr int Setting1 = 1; constexpr QLatin1String SomeOtherSetting = "ABCD"; // ... }
But it's entirely up to you which solution you prefer more.
-
@sierdzio Thank you very much. How would i need to update the path? It looks like this right now:
How can i for example put these files into a subfolder named "DockableItemsFolder"if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) qt_add_executable(EditorWIPNeu MANUAL_FINALIZATION ${PROJECT_SOURCES} CustomDockableItemList.cpp CustomDockableItemList.h }
-
@StudentScripter said in Save Programm Settings internally + how to organize with folders?:
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) qt_add_executable(EditorWIPNeu MANUAL_FINALIZATION ${PROJECT_SOURCES} DockableItemsFolder/CustomDockableItemList.cpp DockableItemsFolder/CustomDockableItemList.h }
-
@sierdzio Thank you very much and well, guess i have to use something different than headders cause the values should be modifiable and shall be saved as new standards when closing the application.
open application --> set Standard values --> interact with application and change settings--> close Application and save new changed values as new standards
Guess qrc is the way to go here or qsettings.
-
@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.