I would do it like this:
Lets say that we have two functions member of a class to load and save the scores.
To use the registry, you have to specify the application name and editor:
QSettings settings("<MyEditorName>","<myAppName>");
saveScores(settings);
loadScores(settings);
to use a file, you have to provide the file path and format:
QSettings settings("<filepath>",QSettings::iniFormat);
saveScores(settings);
loadScores(settings);
from your code and the documentation; the member function would be as follow.
The class countains a vector of scores (QVector mScores)
Function to save the scores:
void myClass::saveScores(QSettings& iSettings)
{
iSettings.beginGroup("Scores");
iSettings.beginWriteArray("results");
for(int i=0; i<mScores.count();i++)
{
iSettings.setArrayIndex(i);
iSettings.setValue("result",mScores[i]);
}
iSettings.endArray();
iSettings.endGroup();
}
Function to load the scores
void myClass::loadScores(QSettings& iSettings)
{
iSettings.beginGroup("Scores");
int size = iSettings.beginReadArray("results");
mScores.resize(size);
for(int i=0;i<size;i++)
{
iSettings.setArrayIndex(i);
mScores[i] = iSettings->value("result").toInt();
}
iSettings.endArray();
iSettings.endGroup();
}
I am using groups to provide better visibility in the saving file but you can remove them
iSettings->endArray()
– Benzocaine