PDA

View Full Version : QSettings



JeanC
27th February 2011, 15:16
Hello,

I have difficulty supplying arguments to QSettings::value()
This is in the settings file:



[domains]
1=dyndns

[dyndns]
type=dyndns


Now if I call
qDebug() << ini.value("dyndns/type").toString();
I get "dyndns"

But if I call

ini.beginGroup("domains");
QStringList l = ini.allKeys();
for (int i = 0; i < l.size(); i++)
{
QString Domain = ini.value(l.at(i)).toString(), S = QString("%1/type").arg(Domain), Type = ini.value(S).toString();
qDebug() << Domain << S << Type;
}


I don't get the Type string, it's empty, I get "dyndns" "dyndns/type" ""

Thanks.

wysota
27th February 2011, 16:00
Line #5 should read:

QString Domain = ini.value(l.at(i)).toString(), Type = ini.value("type").toString();

JeanC
27th February 2011, 16:31
Thanks,
I tried it but Type is still empty.

wysota
27th February 2011, 16:47
Ouch, sorry I didn't look at the ini file. This is the correct code:

ini.beginGroup("domains");
QStringList groups;
foreach(const QString &key, ini.childKeys()) groups << ini.value(key).toString();
ini.endGroup();
foreach(const QString &group, groups){
QString S = QString("%1/type").arg(group), Type = ini.value(S).toString();
qDebug() << group << S << Type;
}
Line #7 can also be replaced with:

ini.beginGroup(group);
QString Type = ini.value("type").toString();
ini.endGroup();

JeanC
27th February 2011, 16:52
Thanks this works, I already had a suspicion about forgetting endGroup().
Nice code, I didn't know about the foreach() yet, I'm gonna study it.