Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
QSettings on macOS has unexpected flattening of arrays and groups
root | |--- Array | | | |--- Index | | | |--- Value1 | |--- Value2 | |--- Group | |--- Value1 |--- Value2
Instead it creates the keys flattened as children of the root:
root | |--- Array.Index.Value1 |--- Array.Index.Value2 |--- Group.Value1 |--- Group.Value2
Is this intended behaviour? The underlying CFPreferences API should be capable of building correct parent-child structures.
JonB last edited by JonB
I'm not sure if this has any relevance to MacOS. In
QSettingsoutput groups/arrays always produce "flat" keys, with a counting number for the index. The reason is that that the Windows
.inifile format has no "nested structure", it is a file of
key=valueformat, with (optional) occasional (single-level)
[Section]lines to divide into sections.
Under Windows/Linux I believe it stores group/array elements like
element/index=valuewhere you show the separator as
.; but that's an internal detail.
Why did you expect otherwise? The only guarantee of the
QSettingsoutput is that code should be able to read it back to produce the same data as was used to create it. It is not guaranteed to be "human readable". Under Windows it does not even promise to match expectations of other
.inifiles and so be compatible with them, only that
QSettingscan be used to write & read its own files.
I don't know anything about "underlying CFPreferences API".
On windows the QSettings values are stored in the Registry and as I just have seen the nested values are stored as a binary. Though you are right, I just expected it to use the native api calls properly because it can.
JonB last edited by JonB
On windows the QSettings values are stored in the Registry
No, not necessarily!
QSettings is an abstraction around these technologies, enabling you to save and restore application settings in a portable manner.
See https://doc.qt.io/qt-5/qsettings.html#Format-enum and the various overloads of
QSettings()which allow programmer to choose how/where the settings are actually stored. Also see https://doc.qt.io/qt-5/qsettings.html#section-and-key-syntax and https://doc.qt.io/qt-5/qsettings.html#platform-specific-notes, etc.
In previous discussions of this topic, the best we have come up with is: you can assume that settings saved from
QSettingswill be readable back via
QSettings. Any further assumptions --- e.g.
QSettingswill be able to read files/settings created outside of
QSettings, or vice versa --- are "unwarranted": they may work, or may work sometimes, or may not.
So that means that the custom 'style' is intentional. That answers my question.
Thanks for your answer!