PDA

View Full Version : Problems with QSettings



franco.amato
9th April 2010, 03:20
Hi,
I would load some settings from an ini file.
Some settings are QColors so in my ini file I have a color section with many points so:

[colors]
background=
waveform=
timeline=
markers=
selection=

I would set some default values living empty the color fields in the ini file so I would that Qt load the default values so:


QColor defColor = Qt::white; //default value
QVariant colVariant = defColor; //convert in QVariant
m_bgColor = settings.value( "background", colVariant ).value<QColor>(); // I would Qt::white as default value

but debuggind it says that m_bgColor is invalid and doesn't has the desired value.

Where I'm wrong?

Best

borisbn
9th April 2010, 04:07
In your ini-file background equals empty string, wich is invalid

ComaWhite
9th April 2010, 04:40
In your ini-file background equals empty string, wich is invalid

Like this guy says, if there is a setting in the ini file it will mean there is a value even if there is not. If it uses a default value, like you say White. The entry will simply be not there. So remove the background= from the ini file and it will return white

Always remember, default values will not be listed.
entries listed have values even if empty

franco.amato
9th April 2010, 19:09
Like this guy says, if there is a setting in the ini file it will mean there is a value even if there is not. If it uses a default value, like you say White. The entry will simply be not there. So remove the background= from the ini file and it will return white

Always remember, default values will not be listed.
entries listed have values even if empty

How can I set a default value in the ini file for a QColor? For example I would have white as default in the ini file and
If the user would change it I'll update the value

ComaWhite
10th April 2010, 05:20
Well, like I said. If the user modified it, the entry will be in the ini, if not it won't be there.