-
Suggestion
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
None
-
None
PROBLEM DESCRIPTION:
QSettings is stored in a file that is overwritten as a whole. In case of disk full condition or an app crash system settings data is prone to data loss because the file is completely deleted at some point.
SOLUTION:
The attached patch implements the class SqliteSettingsFormat that can be registered with QSettings::registerFormat to serve as an SQLite backstore for QSettings.
It maintains the SQLite database for settings and only inserts/updates/deletes records, and never deletes the whole file.
CAVEATS:
- QSettings::registerFormat interface uses QIODevice and assumes that the file is written sequentially. SQLite can't use QIODevice, so SqliteSettingsFormat creates the database file separately. It assumes that QIODevice is QFile (which should always be the case) and derives the database file name from it.
- QSettings object using SqliteSettingsFormat cannot be instantiated at the global scope. It has to be instantiated in the "main" function, because it depends on the Sql driver that is registered in the global context.
- QKeySequence isn't handled
- Due to the first caveat and the fact that SqliteSettingsFormat uses Sql and QSettings is in Core and doesn't use Sql, I am not sure where to place SqliteSettingsFormat in the Qt hierarchy.
USE EXAMPLE:
QSettings localSettingsObject(
QSettings::registerFormat("x", SqliteSettingsFormat::readFile, SqliteSettingsFormat::writeFile),
QSettings::UserScope, "Company", "app");
CONCLUSION:
I think such module is very useful since it prevents the data loss, and should be integrated into Qt. Please modify it and put it into the appropriate place.