Read Several Groups in INI file from QSettings
i need to read all the groups in my ini file... how can i do this?
this is my ini file
Code:
[sys_1]
val1 = 10
val2 = 23
val3 = 23
[sys_2]
val1 = 56
val2 = 2
val3 = 27
[sys_3]
val1 = 84
val2 = 65
val3 = 12
this is the code im using
Code:
settings.beginGroup("SYS_1");// How to change this to read 'n' number of groups ??
foreach
(const QString &childKey, childKeys
) {
Keys << childKey;
values << settings.value(childKey).toString();
}
settings.endGroup();
settings.beginGroup("SYS_1");// How to change this to read 'n' number of groups ??
Re: Read Several Groups in INI file from QSettings
You can read all group using QSettings::childGroups()
for example
Code:
Q_FOREACH (QString group, settings.
childGroups()) { settings.beginGroup(group);
foreach
(const QString &childKey, childKeys
) {
Keys << childKey;
values << settings.value(childKey).toString();
}
settings.endGroup();
}
or, if you read ONLY "sys_*" groups
Code:
Q_FOREACH (QString group, settings.
childGroups()) { if (!group.startsWith("sys_"))
continue;
settings.beginGroup(group);
foreach
(const QString &childKey, childKeys
) {
Keys << childKey;
values << settings.value(childKey).toString();
}
settings.endGroup();
}
Re: Read Several Groups in INI file from QSettings
How Can i add a new Group using QSettings??
my ini is this
Code:
[sys_1]
val1 = 10
val2 = 23
val3 = 23
[sys_2]
val1 = 56
val2 = 2
val3 = 27
[sys_3]
val1 = 84
val2 = 65
val3 = 12
i need to add [sys_4]..
Re: Read Several Groups in INI file from QSettings
Using setValue
Code:
settings.addGroup("[sys_4]");
settings.setValue("val1", 10);
settings.setValue("val2", 20);
settings.setValue("val3", 30);
settings.endGroup();