I have an application I'm writing using Qt 4.5.2 on Windows. I'm storing some settings in an INI file and using QSettings to load and save the settings. I'd like to have some comments in the INI file.
For example:
; Meta-info to store with the file
[General]
MainWindow\size=@Size(1280 600)
MainWindow\pos=@Point(0 300)
Debugging=true
However, I've found when I load the settings file with
QSettings settings( "settings.ini", QSettings::IniFormat );
the comments are stripped out of the file. The INI file is re-written after loading by a call to QSettings::sync() (this is done automatically by the constructor). Is there a way to preserve the comments after syncing?
Preemptive comments:
QSettings
has no concept of "save". All the changes you do to it is considered to be final, and written to disk often and transparently.
In the documentation of QSettings
, there is no mention about comments in ini files. It does makes some sense: after all, it can be a registry value, too. Treat it like a generated file: it is one.
Here's my suggestion:
[General]
Comment = @String(Meta-info to store with the file)
MainWindow\size=@Size(1280 600)
MainWindow\pos=@Point(0 300)
Debugging=true
I don't know if it works, play around with it to see how it actually stores the string. Oh, and make sure you either set it from code or document it properly, to avoid accidentally using the same identifier from within the program.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With