Save QList<int> to QSettings
Posted
by Tobias
on Stack Overflow
See other posts from Stack Overflow
or by Tobias
Published on 2010-03-16T08:20:42Z
Indexed on
2010/03/16
8:26 UTC
Read the original article
Hit count: 391
Hello,
I want to save a QList<int>
to my QSettings without looping through it.
I know that I could use writeArray() and a loop to save all items or to write the QList to a QByteArray and save this but then it is not human readable in my INI file..
Currently I am using the following to transform my QList<int>
to QList<QVariant>
:
QList<QVariant> variantList;
//Temp is the QList<int>
for (int i = 0; i < temp.size(); i++)
variantList.append(temp.at(i));
And to save this QList<Variant>
to my Settings I use the following code:
QVariant list;
list.setValue(variantList);
//saveSession is my QSettings object
saveSession.setValue("MyList", list);
The QList is correctly saved to my INI file as I can see (comma seperated list of my ints)
But the function crashes on exit.
I already tried to use a pointer to my QSettings object instead but then it crashes on deleting the pointer ..
© Stack Overflow or respective owner