Created
July 9, 2012 18:36
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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