PDA

View Full Version : QSettings problem in windows



kurrachow
29th March 2011, 04:54
I have a program in windows platform ...........

I have just made up a registry like this....

chow
kurra
Settings

in the Settings key i have some string values like say "showDialogOnPrinting" which data is not set...

Now in my program i set my organisationName to chow

and my application name to kurra

and Code like this....


QSettings settings;
settings.beginGroup("Settings");
bool shDialog = settings.value("showDialogOnPrinting",false);
checkboxShDialog->setChecked(shDialog);


here the settings.value("showDialogOnPrinting",false); is supposed to set false if there is no value(According to docs the false in this case is the default/fallback value).

But that didnt set false in the registry....and the code was successfully executed..

when i change the value to true in the registry, it works good,it fetches the true and checks the box....

stampede
29th March 2011, 07:24
But that didnt set false in the registry....and the code was successfully executed..
It will not set the value in registry, it will return false if there is no such key in your settings, or it's value is not convertible to bool. So the variable shDialog will be true/false depending on the value in settings. Reading values from settings will not change the registry.
In order to set a value in registry you need to use


bool b = ...;
...
QSettings settings;
settings.beginGroup("Settings");
settings.setValue("showDialogOnPrinting",b);

mcosta
29th March 2011, 07:27
HI,

try using QVariant::toBool() when you reading value.



QSettings settings;
settings.beginGroup("Settings");
bool shDialog = settings.value("showDialogOnPrinting",false).toBool();
checkboxShDialog->setChecked(shDialog);