QSettings::beginWriteArray() produces incorrect output under Linux (bug?)
-
@JonB said in QSettings::beginWriteArray() produces incorrect output under Linux (bug?):
The only bit I care about is whether the file ends up with forward or backward slashes!
The slashes in the doc could be just for demonstration purposes. Just to show the
QSetting
hierarchy?!-
The generated keys will have the form
What if "form" is meant in terms of hierarchy, separated by single slashes and not showing the actual content of the save file?!
If this is the case, it's very misleading, but occording to
QSettings
doc (at least on Windows)QSettings
ignores '\' and converts them to '/' anyway...So it could be an unfortunately worded example for this:
- logins
-------- 1
------------- userName
------------- password
-------- 2
------------- userName
------------- passwordEdit:
Looks like arrays always have backslashes (if they should? I dont know...)
https://forum.qt.io/topic/79494/qsetting-array/4Just found a version of
QSettings
code online.
https://github.com/radekp/qt/blob/master/src/corelib/io/qsettings.cppvoid QSettingsPrivate::processChild(QString key, ChildSpec spec, QMap<QString, QString> &result) { if (spec != AllKeys) { int slashPos = key.indexOf(QLatin1Char('/')); // ### SLASH if (slashPos == -1) { if (spec != ChildKeys) return; } else { if (spec != ChildGroups) return; key.truncate(slashPos); } } result.insert(key, QString()); } void QSettingsPrivate::beginGroupOrArray(const QSettingsGroup &group) { groupStack.push(group); if (!group.name().isEmpty()) { groupPrefix += group.name(); groupPrefix += QLatin1Char('/'); // # SLASH!! } }
In addition to that,
QSettings
uses theQDir::separator()
which indeed returns a single slash ('/') on my Linux system and a backslash on Windows....I really don't know where the backslash is coming from and WHY? :-)
-
-
@JonB said in QSettings::beginWriteArray() produces incorrect output under Linux (bug?):
@Pl45m4
From your https://forum.qt.io/topic/79494/qsetting-array/4 it looks like it is producing\
s elsewhere.Just because others face the same issue or behavior, it doesn't mean that it's intended or correct :)
Could be wrong (buggy) since years / many releases, but seems to work :)@JonB said in QSettings::beginWriteArray() produces incorrect output under Linux (bug?):
Then it's perhaps just a docs issue.
The second part of my post (the Qt source code) shows that it's not a doc issue. You can also find the same comment in the source code ("The generated keys will have the form.... bla...")... Really weird...
-
What's the problem as long as beginReadArray() can read them later on?
-
@Christian-Ehrlicher
At the time I raised the question I did not yet know whether it could be read OK. Now I am pleased to report it does. I merely asked to see if it was the same for others. I do not know if there any other consequences, hopefully not.So you belong to the "it doesn't matter what the docs say as long as it works" school ;-)
-
Nevertheless, it would be satisfying (for me as well) if someone could explain where the backslashes come from, because even in current sources arrays start explicitly with '/'. (https://github.com/radekp/qt/blob/master/src/corelib/io/qsettings.cpp#L393)
-
Nevertheless, it would be satisfying (for me as well) if someone could explain where the backslashes come from
All backslashes live in a land of their own, where everything is the wrong way round. They emanate from there, mystically. And sometimes arrive in pairs.
I will raise a report on the Qt bug forum tomorrow and they can decide whether it's a documentation or behaviour issue.
-
@JonB said in QSettings::beginWriteArray() produces incorrect output under Linux (bug?):
So you belong to the "it doesn't matter what the docs say as long as it works" school ;-)
No, but to the 'I don't care about the internals as long as the library can read it again'. Or do you really care how e.g. QDataStream encodes and decodes the stuff as long as it is doing what you expect?
-
@Christian-Ehrlicher
So are you saying you'd rather I didn't report it? When the docs choose to tell me the file will look like such & such and I try it and it does not, I shouldn't question it, shouldn't ask about it here but just assume it's fine? I don't understand your point/suggestion? -
From my pov that's only a documentation error.
-
@Christian-Ehrlicher
No problem. I'll log it tomorrow, if it's only docs and the behaviour is intended then at least someone (might be you!) will have seen it and can decide. -
For right or for wrong, raised https://bugreports.qt.io/browse/QTBUG-81951. Hopefully someone will check whether it's only a documentation issue or if it has any consequences.