PDA

View Full Version : QSettings::value() does not return value.



zEeLi
7th June 2007, 14:58
Hello fellow QT devs.

Here goes my problem:

I have QStringList which contains strings of registry paths
i.e.

\Profile Name\Info\Name
\Profile Name\Info\Lenght
\Profile Name\Size\Width
\Profile Name\Size\Height

and so on..

I need to get values from those paths


...
QSettings settings;
QStringList keys = settings.allKeys();

settings.beginReadArray("Profile Name");

for(int i = 0; i < keys.size(); i++)
{
QString key = keys.at(i);
QVariant value = settings.value(key, QVariant::Invalid);
...
}
...


That's the code I'm trying to use. value() does not return the proper value(no value returned at all!).How can I get the value-function to return the value of that specific key?

Your help is appreciated.


- Eeli Reilin

^NyAw^
7th June 2007, 15:29
Hi,



#
QSettings settings;
#
QStringList keys = settings.allKeys();
#

#
settings.beginReadArray("Profile Name");


You are getting the strings from "settings" variable and it has any string yet. Then you insert "Profile Name" to settings and you think that "keys" will auto update the readed value.



QSettings settings;
settings.beginReadArray("Profile Name"); //First you have to write the strings
QStringList keys = settings.allKeys(); //then you can obtain them

for(int i = 0; i < keys.size(); i++)
{
QString key = keys.at(i);
QVariant value = settings.value(key, QVariant::Invalid);
...
}

zEeLi
11th June 2007, 10:20
Hi,



You are getting the strings from "settings" variable and it has any string yet. Then you insert "Profile Name" to settings and you think that "keys" will auto update the readed value.



QSettings settings;
settings.beginReadArray("Profile Name"); //First you have to write the strings
QStringList keys = settings.allKeys(); //then you can obtain them

for(int i = 0; i < keys.size(); i++)
{
QString key = keys.at(i);
QVariant value = settings.value(key, QVariant::Invalid);
...
}


Yea, but the values are already in the registry :crying:
value() always returns the default value, which is in my case QVariant::Invalid

Damnit, why is this so damn hard?


- Eeli Reilin

fullmetalcoder
11th June 2007, 10:25
Yea, but the values are already in the registry :crying:
value() always returns the default value, which is in my case QVariant::Invalid

Damnit, why is this so damn hard?

The thing is that you do not supply a valid registry path to QSettings (http://doc.trolltech.com/latest/qsettings.html) constructor... Do you expect it to automagically figure out where your settings are stored? Basically, when you don't pass any parameters to QSettings ctor it does automagically find a location (http://doc.trolltech.com/4.2/qsettings.html#QSettings-5) to store them but I doubt it's the one you expect...