QSettings how to remove elements from array?
Unsolved
General and Desktop
-
wrote on 9 Apr 2016, 02:29 last edited by
I have a array save in QSettings
I can modify the element
But I don't know how to remove it
Anybody know? -
wrote on 9 Apr 2016, 06:24 last edited by
Hi ,
Did you tryremove
? http://doc.qt.io/qt-4.8/qsettings.html#remove -
Hi ,
Did you tryremove
? http://doc.qt.io/qt-4.8/qsettings.html#remove -
wrote on 9 Apr 2016, 07:24 last edited by Ratzz 4 Sept 2016, 07:25
I did you get you clearly.. can you show the code or explain me more?
-
wrote on 9 Apr 2016, 07:33 last edited by
@Ratzz okay
//this is I write a array QSettings setting("TEST","demo1"); setting.beginWriteArray("array1"); for(auto i=0;i<10;i++){ setting.setArrayIndex(i); setting.setValue("demo","value"+QString::number(i)); } setting.endArray();
//this is I read a array auto size = setting.beginReadArray("array1"); for(auto i=0;i<size;i++){ setting.setArrayIndex(i); qDebug()<<setting.value("demo"); } setting.endArray();
//read the array and remove setting.beginReadArray("array1"); setting.setArrayIndex(5); setting.remove("demo"); setting.endArray(); //the result is //QVariant(QString, "value0") //QVariant(QString, "value1") //QVariant(QString, "value2") //QVariant(QString, "value3") //QVariant(QString, "value4") //QVariant(Invalid) //QVariant(QString, "value6") //QVariant(QString, "value7") //QVariant(QString, "value8") //QVariant(QString, "value9")
//write the array and remove setting.beginWriteArray("array1"); setting.setArrayIndex(5); setting.remove("demo"); setting.endArray(); //result QVariant(QString, "value0") QVariant(QString, "value1") QVariant(QString, "value2") QVariant(QString, "value3") QVariant(QString, "value4") QVariant(Invalid)
Is it clearly?
-
wrote on 9 Apr 2016, 07:54 last edited by Ratzz 4 Sept 2016, 07:55
I think you need to set back the value to QSettings after you remove.
1/7