Reputation: 30895
im using QSettings to write to ini file and loading the configuration in application start my question is once i load value by key does QSettings object keeps the key value in memory or its reads the value from the ini file ?
Upvotes: 2
Views: 2684
Reputation: 2643
The values are handled in memory, so changing the file doesn't change the QSettings object you have in memory and vice versa.
edit:
Call sync to update to/from file.
It saves values you have modified and reads any values you didn't modify but were modified in the file.
example
// settings.ini contains keys Hello and Hi, which contain both "-"
QSettings settings("settings.ini", QSettings::IniFormat),
// in settings object: *Hello* contains *-* and *Hi* contains *-*
// in settings.ini: *Hello* contains *-* and *Hi* contains *-*
settings.setValue("Hello", "World");
// settings.ini is modified, Hi now contains World
// in settings object: *Hello* contains *World* and *Hi* contains *-*
// in settings.ini: *Hello* contains *-* and *Hi* contains *World*
settings.sync();
// in settings object: *Hello* contains *World* and *Hi* contains *World*
// in settings.ini: *Hello* contains *World* and *Hi* contains *World*
Or that's how it should work if I remember correctly
out of the qt (5.10) docs to QSettings::sync() - This function is called automatically from QSettings's destructor and by the event loop at regular intervals, so you normally don't need to call it yourself.
– lumos0815
Upvotes: 4