PDA

View Full Version : Update GUI from Config File



SiddhantR
17th September 2013, 12:00
Hi,
I am making a GUI in which based on user login a certain number of buttons are supposed to be enabled and the rest disabled. I have to do this with the help of a config file.
Can anyone please share any examples or references if they know.
Thank you :)

wysota
17th September 2013, 12:41
QFile

QSettings

QXmlStreamReader

SiddhantR
17th September 2013, 13:25
I have already had a look at it. I got how to read from ini files and set settings for color and all. However I am not able to understand how to apply the logic for buttons. For eg. In telkon every button has a hexadecimal argument which decides which property of the button is to be changed. Is their anything similar in Qt?

Thank You

wysota
17th September 2013, 14:41
Properties in Qt are referenced by their names. You can use a generic QObject::setProperty() call to modify any available property.

SiddhantR
18th September 2013, 09:40
I am trying QSettings now. I am following the following approach. I have taken two buttons and I am trying to enable and set style sheet of button 1 when I click button 2.

[button]

button1 = 1;
stylesheet = background-color:green;

And in the button 2 click slot

QSettings settings("/root/config.ini",QSettings::IniFormat);
settings.beginGroup("button);
button1->setEnabled(settings.value("button1").toBool());
button1->setStylesheet(settings.value("stylesheet").toString());

But this doesn't seem to be working. Where am I going wrong?

wysota
18th September 2013, 09:44
What exactly "does not seem to be working"? Are the values from the settings file read correctly? Are the property values set correctly? Do they contain correct or incorrect values? Have you checked all that?

SiddhantR
18th September 2013, 10:08
Actually the enable disable part is work. I am not able to setStylesheet using the above method.
Thanks for the reply.

wysota
18th September 2013, 10:16
You mean that after a call to setStylesheet(), a call to stylesheet() returns the old value?

SiddhantR
18th September 2013, 10:24
Yes the stylesheet doesn't show the color change.

wysota
18th September 2013, 10:29
Could you run this code and show us the output?


qDebug() << "Initial:" << button1->stylesheet();
qDebug() << "To be set:" << settings.value("stylesheet").toString();
button1->setStylesheet(settings.value("stylesheet").toString());
qDebug() << "After change:" << button1->stylesheet();

SiddhantR
18th September 2013, 10:37
Still no change

wysota
18th September 2013, 10:41
Still no change to what? What is the output of the code I told you to run?

SiddhantR
18th September 2013, 10:44
The button doesnt change the background color to green. And the output is
Initial: ""
To be set: ""
After Chane: ""

wysota
18th September 2013, 10:50
So if you change an empty string to an empty string the string is still empty. That's not very surprising, is it?

SiddhantR
18th September 2013, 10:54
Ohhh Is it because it is considering the part after ':' in stylesheet as comment? Can you suggest me what can be done?

wysota
18th September 2013, 11:00
I don't know what "it" considers. I know that you're setting an empty string as the stylesheet therefore probably your code for reading the settings is incorrect.

ChrisW67
19th September 2013, 00:27
Ohhh Is it because it is considering the part after ':' in stylesheet as comment? Can you suggest me what can be done?

Surely if it were doing that the style sheet would be set to "background-color" but your output tells us it is being set to an empty string.

The semi-colon, i.e. ';' not ':', is a comment introducer in INI files. If you need to embed semi-colons in strings then you need to quote them.