PDA

View Full Version : Save a QStringList to arrey in QSettings



halvors
4th August 2010, 10:55
How do i save a QStringList to a arrey in Settings?



QString myvalue; //This have value from before.

settings settings(Me, App);
settings.beginGroup("ServerManager");
settings.beginWriteArray("ServerItems");
settings.setValue("ServerItem", myvalue);
settings.endArray();
settings.engGroup();


Can anyone help me?

Lykurg
4th August 2010, 11:00
Yes, but what do you want to know what the docs are not providing? Isn't there a good example: QSettings::beginWriteArray()?

EDIT: And a QStringList is (almost) nothing else than QList<QString>

halvors
4th August 2010, 11:12
As this:



QStringList myvalue;

QSettings settings;
settings.beginWriteArray("ServerItems");
for (int i = 0; i < myvalue.size(); ++i) {
settings.setArrayIndex(i);
settings.setValue("ServerItem", list.at(i).myvalue);
}
settings.endArray();


Please correct if i am wrong...

Lykurg
4th August 2010, 11:20
is myvalue == list? How do you normally access a string from your string list. How would you normally loop through your string list?

halvors
4th August 2010, 11:56
Its a QStringList with 4 values (strings). Is the code correct?

Lykurg
4th August 2010, 13:14
Damn, NO, it's not correct. Try it and you see it will not work. And all necessary hints I have already given.

(And for future you should may be take our Newbie section!)

halvors
5th August 2010, 00:24
Well, i am ask. Can you please help me get it work?

Lykurg
5th August 2010, 05:57
Please, next time use the newbie section. And I wont provide the code.

When you have this string list:
QStringList list;
list << "read" << "the" << "documentation";How would you iterate through the items and show them using qDebug()? All infos you can find here: QStringList.

If you now that, just combine it with the array writing.

xalam
7th October 2015, 21:52
As this:



QStringList myvalue;

QSettings settings;
settings.beginWriteArray("ServerItems");
for (int i = 0; i < myvalue.size(); ++i) {
settings.setArrayIndex(i);
settings.setValue("ServerItem", list.at(i).myvalue);
}
settings.endArray();


Please correct if i am wrong...

Where is `list` defined? Even in the documentation, it is the same but I don't understand why list is not defined. It sure come up as undeclared identifier and doesn't build.

In my case I only want to save QStringArray to QSettings, how to do that?