QSettings on macOS has unexpected flattening of arrays and groups
-
Good morning,
I encountered a strange behaviour on macOS when using the QSettings. When data is stored with the beginGroup() or beginWriteArray() isn't it intended to create a nested structure like
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.
-
@vic-ju
I'm not sure if this has any relevance to MacOS. InQSettings
output groups/arrays always produce "flat" keys, with a counting number for the index. The reason is that that the Windows.ini
file format has no "nested structure", it is a file ofkey=value
format, with (optional) occasional (single-level)[Section]
lines to divide into sections.Under Windows/Linux I believe it stores group/array elements like
element\index=value
orelement/index=value
where you show the separator as.
; but that's an internal detail.Why did you expect otherwise? The only guarantee of the
QSettings
output 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.ini
files and so be compatible with them, only thatQSettings
can 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
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
QSettings
will be readable back viaQSettings
. Any further assumptions --- e.g.QSettings
will be able to read files/settings created outside ofQSettings
, or vice versa --- are "unwarranted": they may work, or may work sometimes, or may not.