Skip to content

Instantly share code, notes, and snippets.

@jcfr
Created July 9, 2012 18:36
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcfr/3078087 to your computer and use it in GitHub Desktop.
Save jcfr/3078087 to your computer and use it in GitHub Desktop.
Qt example illustrating how to write list of QVariantMap into a settings file.
// Qt includes
#include <QSettings>
#include <QVariantMap>
// STL includes
#include <cstdlib>
int main(int, char*[])
{
QSettings settings("qVariantMapToSettings.ini", QSettings::IniFormat);
QList<QVariantMap> list;
{
QVariantMap map;
map["string"] = QVariant("bar");
map["bool"] = QVariant(true);
list << map;
}
{
QVariantMap map;
map["string"] = QVariant("foo");
map["bool"] = QVariant(false);
list << map;
}
settings.clear();
settings.beginWriteArray("settings");
for (int i = 0; i < list.size(); ++i)
{
settings.setArrayIndex(i);
settings.setValue("setting", list.at(i));
}
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment