QSettings array of values (rather than groups)
-
QSettings has support for arrays, as shown in the documentation. Assuming INI format, an array might expand to something like:
[foo] size=2 [foo/0] bar=3 baz=4 [foo/1] bar=5 baz=6
which is perfectly acceptable, but I want to know if I could make something like the following:
[foo] size=2 0=1 1=2
that is, an array of values rather than groups of values.
If this is not possible I will just make something like:
[foo/0] value=1 [foo/1] value=2
or write some functions to manually put the size and items, but I would rather not do that if possible.
Is what I'm describing possible? I've tried passing an empty string to
QSettings::value
but I get an error. -
QSettings has support for arrays, as shown in the documentation. Assuming INI format, an array might expand to something like:
[foo] size=2 [foo/0] bar=3 baz=4 [foo/1] bar=5 baz=6
which is perfectly acceptable, but I want to know if I could make something like the following:
[foo] size=2 0=1 1=2
that is, an array of values rather than groups of values.
If this is not possible I will just make something like:
[foo/0] value=1 [foo/1] value=2
or write some functions to manually put the size and items, but I would rather not do that if possible.
Is what I'm describing possible? I've tried passing an empty string to
QSettings::value
but I get an error.You shouldn't worry about how it is written, when you read the file with the same program again. Do you want to read this file with another program?
To write arrays, there is
beginWriteArray
andbeginReadArray
- https://doc.qt.io/qt-5/qsettings.html#beginWriteArray
- https://doc.qt.io/qt-5/qsettings.html#beginReadArray
Documentation says:
The generated keys will have the form
logins/size logins/1/userName logins/1/password logins/2/userName logins/2/password logins/3/userName logins/3/password
Which is close to what you want, right?
Edit:
Just remembered this topic
Btw: The examples in the documentation of
QSettings
are pretty messed up :)
The internal stuff thatQSettings
does seems to be a bit different from what is in the documentation... but as long as it works...See: https://bugreports.qt.io/browse/QTBUG-81951
... and a typo / mistake in the examples made it even to the Qt6 documentation :)
https://doc-snapshots.qt.io/qt6-dev/qsettings.html#beginWriteArray
list.at(i)
instead oflogins.at(i)
In the code sample there is nolist
;-) -
You shouldn't worry about how it is written, when you read the file with the same program again. Do you want to read this file with another program?
To write arrays, there is
beginWriteArray
andbeginReadArray
- https://doc.qt.io/qt-5/qsettings.html#beginWriteArray
- https://doc.qt.io/qt-5/qsettings.html#beginReadArray
Documentation says:
The generated keys will have the form
logins/size logins/1/userName logins/1/password logins/2/userName logins/2/password logins/3/userName logins/3/password
Which is close to what you want, right?
Edit:
Just remembered this topic
Btw: The examples in the documentation of
QSettings
are pretty messed up :)
The internal stuff thatQSettings
does seems to be a bit different from what is in the documentation... but as long as it works...See: https://bugreports.qt.io/browse/QTBUG-81951
... and a typo / mistake in the examples made it even to the Qt6 documentation :)
https://doc-snapshots.qt.io/qt6-dev/qsettings.html#beginWriteArray
list.at(i)
instead oflogins.at(i)
In the code sample there is nolist
;-)@Pl45m4 said in QSettings array of values (rather than groups):
The internal stuff that QSettings does seems to be a bit different from what is in the documentation...
It's not - how the backend does write out the data is not specified (and can't since e.g. the registry is other than a plain ini file)
... and a typo / mistake in the examples made it even to the Qt6 documentation :)
How about providing a patch instead?
-
@Pl45m4 said in QSettings array of values (rather than groups):
The internal stuff that QSettings does seems to be a bit different from what is in the documentation...
It's not - how the backend does write out the data is not specified (and can't since e.g. the registry is other than a plain ini file)
... and a typo / mistake in the examples made it even to the Qt6 documentation :)
How about providing a patch instead?
@Christian-Ehrlicher said in QSettings array of values (rather than groups):
How about providing a patch instead?
Where? :)
-
@Christian-Ehrlicher said in QSettings array of values (rather than groups):
How about providing a patch instead?
Where? :)
-
Haha, @Christian-Ehrlicher , "submit a patch" seems to be your go-to advice :)
I have no need to do so. As I said, I can work around this.
I was just wondering if there was a way to do what I'm trying to do.
-
You shouldn't worry about how it is written, when you read the file with the same program again. Do you want to read this file with another program?
To write arrays, there is
beginWriteArray
andbeginReadArray
- https://doc.qt.io/qt-5/qsettings.html#beginWriteArray
- https://doc.qt.io/qt-5/qsettings.html#beginReadArray
Documentation says:
The generated keys will have the form
logins/size logins/1/userName logins/1/password logins/2/userName logins/2/password logins/3/userName logins/3/password
Which is close to what you want, right?
Edit:
Just remembered this topic
Btw: The examples in the documentation of
QSettings
are pretty messed up :)
The internal stuff thatQSettings
does seems to be a bit different from what is in the documentation... but as long as it works...See: https://bugreports.qt.io/browse/QTBUG-81951
... and a typo / mistake in the examples made it even to the Qt6 documentation :)
https://doc-snapshots.qt.io/qt6-dev/qsettings.html#beginWriteArray
list.at(i)
instead oflogins.at(i)
In the code sample there is nolist
;-)@Pl45m4 I realize now that what I'm trying to do doesn't make much sense because even if I could write what I want to the settings, I would have no good way to read it. I'll just use a workaround.
-
@Pl45m4 I realize now that what I'm trying to do doesn't make much sense because even if I could write what I want to the settings, I would have no good way to read it. I'll just use a workaround.
The "provide a patch" was directed to me :)
Because theQSetting
documentation has a mistake -
The "provide a patch" was directed to me :)
Because theQSetting
documentation has a mistake@Pl45m4 Ah, alright. I will probably overload QDataStream& operator<< and operator>> for QVector<T> where it just puts the size and then the items.