Append data on a file using QSetting
-
Is it possible to keep the old data and append the new data everytime the program runs on QSetting;
QString file = QApplication::applicationDirPath() + "/sample.ini";
qDebug() << QApplication::applicationDirPath() << endl;
QSettings settings(file, QSettings::IniFormat);
settings.beginGroup("Sample");
settings.setValue("Username", "John");
settings.setValue("Password", "12345678");
settings.endGroup();What happens here is it only keeps new data. I tried adding a count on begingroup function but it error.
-
@LovelyGrace
Don't understand what you mean. Your code reads in the existing settings. You create/overwriteSample/Username
&Sample/Password
. If you mean to instead createSample2/Username
&Sample2/Password
etc. then.beginGroup("Sample2");
would do that.Perhaps you should show what your
.ini
file looks like before & after your code, what you would like it to end up as, and what you tried? -
@LovelyGrace
I would suggest looking into the documentation of QSettings and the section about arrays.https://doc.qt.io/qt-5/qsettings.html#beginReadArray
Seems like that should cover what you want to do.