Get all keys and values as QList<Map> from QSettings

1k Views Asked by At

For my logging system I would like to read out a whole registry folder like this:

​QSettings settings​(​"​HKEY_CURRENT_USER​\\​SOFTWARE​\\​MyApp");
QList<Map> values = settings.getAllValuesAndKeys; // this function does not exists

Is there a way to read out all keys and values like this?

1

There are 1 best solutions below

0
Flippi96 On

To iterate thoughta settings file, you can use the allKeys() function to retrieve all the keys. Then iterate each key and use settings.value(key) to get the associated value. Finally, add all values inside a QMap, and the QMap to the QList. Repeat this for each config file and you'll get all the key-value pairs for a particular config file in a QMap object and finally the desired record in a QList with each QMap that is associated with each config file read.

QSettings settingsFile("mysettingsfile.ini");

QList<QMap<QString, QVariant>> registryList;
QMap<QString, QVariant> settingMap;

QStringList keys = settingsFile.allKeys();
foreach (const QString &key, keys)
    settingMap.insert(key, settingsFile.value(key));

registryList.append(settingMap);