# How to clear current array in QSettings?

• Instead of settings.clear(); which clears the whole settings file, is there a way to only clean a certain Array?

For example, make this:
@[monitored_folders]
size=1
1\item=/usr/share/backgrounds@

into this:
@[monitored_folders]
size=0@

• Just use "method setValue of class QSettings":http://qt-project.org/doc/qt-5.0/qtcore/qsettings.html#setValue and set the value of size to 0. You can find a "simple app with example usage of QSettings here":http://qt-project.org/wiki/How_to_Use_QSettings.

• Lets say settings files contains:

@[monitored_folders]
size=5
1\item=/home/citybong/Pictures
2\item=/home/citybong/Pictures/Animals
3\item=/home/citybong/Pictures/Computer
4\item=/home/citybong/Pictures/Anime & Manga
5\item=/home/citybong/Pictures/Celebrities@

using this code:
@QSettings settings( "Wallch", "MainWindow" );
settings.beginWriteArray("monitored_folders");
settings.setValue("size", 0);
settings.setArrayIndex(0);
settings.setValue("item", "/usr/share/backgrounds");
settings.endArray();
settings.sync();@

i though is would look like this:

@[monitored_folders]
size=1
1\item=/usr/share/backgrounds@

@[monitored_folders]
size=1
1\item=/usr/share/backgrounds
2\item=/home/citybong/Pictures
3\item=/home/citybong/Pictures/Animals
4\item=/home/citybong/Pictures/Computer
5\item=/home/citybong/Pictures/Anime & Manga
6\item=/home/citybong/Pictures/Celebrities@

which eventually works because size=1, but why is this happening?

• You have to use "remove":http://qt-project.org/doc/qt-4.8/qsettings.html#remove with a group (see the second example)

Or the example below:
@
#include <QSettings>
#include <QList>
#include <QStringList>
#include <QDebug>

};

int main(int argc, char *argv[])
{
for ( int i = 0; i < 10; ++i )
{
QString name ( "Name%1");
name = "Pass%1";
}

QSettings settings ("c:/Source/TestQSettings/test.ini", QSettings::IniFormat );

for (int i = 0; i < logins.size(); ++i) {
settings.setArrayIndex(i);
}
settings.endArray();

settings.beginGroup ( "AnotherGroup");
settings.setValue ( "test", 10 );
settings.endGroup ();

QStringList sl = settings.allKeys ();
qDebug() << sl;

settings.remove ("");
settings.endGroup ();

sl = settings.allKeys();
qDebug() << sl;

return 0;


}
@

• I have added a doc note to "Qt4.8 documentation":http://qt-project.org/doc/qt-4.8/qsettings.html I would assume it is also working for Qt5. I appreciate your feedback when tested in Qt5. I would copy then to Qt 5 as well. Thanks .

BTW The example does not fulfill complete your request.
In order to get what you want to have, you can add after removing the group:
@