PDA

View Full Version : problem connect signal - slot



jaca
7th March 2010, 02:04
Hi! I'm trying to connect two QGroupBox. If the groupbox1 checked or clicked the other groupBox2 be disabled or enabled (setEnabled (false) or setEnabled (true)). In Qt Designer works well.


connect(groupBox1, SIGNAL(toggled(bool)), groupBox2, SLOT(setEnabled(bool)));
ou

QObject::connect(groupBox1, SIGNAL(clicked(bool)), groupBox2, SLOT(setEnabled(bool)));

Qt 4.4.3

Any idea? Thanks

lyuts
7th March 2010, 10:19
So, where is the problem? Your code doesn't compile? Or the signal is not emitted? Or slot is not executed?

toutarrive
7th March 2010, 15:20
you are right lyuts, where is the problem...?

jaca
7th March 2010, 22:53
My code compiles. I do not know what is wrong (the signal or slot). The code is correct? Which of the two lines would be the best?

aamer4yu
8th March 2010, 06:08
Are you trying to say your code isnt working well,,
or you want to know which one of toggled() or checked() is better to use ?

netfanatic
8th March 2010, 12:47
make sure that its declared in the onstructor..else it wont work ..........

jaca
8th March 2010, 12:50
I'm trying to say that my code compiles, but does not work well.
When I do:

connect(groupBox1, SIGNAL(toggled(bool)), this, SLOT(setEnabled(bool))); get result.
It seems that the slot is not executed when "this" change by "groupBox2".

squidge
8th March 2010, 18:07
check the output window. If the connect call fails, it will explain why it failed at runtime.

wagmare
9th March 2010, 05:15
yes ... in your console at run time it will display the warning message like this ..
Object::connect: No such slot xxx() or Object::connect: No such signal xxx() or any reason ...

aamer4yu
9th March 2010, 05:22
Can you tell the declaration of groupBox2 ?

lyuts
9th March 2010, 06:55
You need to write your own slot which will call setEnabled() for the second groupbox. Here what the documentation says about toggled(bool) signal:

If the group box is checkable, this signal is emitted when the check box is toggled. on is true if the check box is checked; otherwise it is false. It means that when you enable your first group box the signal is emitted with 'true' and as a result you call setEnabled(true) for your second group box. But as I understand you need to to invert that bool flag. The same thing with clicked() signal.

You need your own signal, smth like this:


connect(groupBox1, SIGNAL(toggled(bool)), this, SLOT(mySlot(bool)));
...
void
mySlot(bool ipFlag)
{
groupBox2->setEnabled(!ipFlag);
}

Lykurg
9th March 2010, 07:46
connect(groupBox1, SIGNAL(toggled(bool)), this, SLOT(mySlot(bool)));
...
void
mySlot(bool ipFlag)
{
groupBox2->setEnabled(!ipFlag);
}

For that you can simply use QWidget::setDisabled().
connect(groupBox1, SIGNAL(toggled(bool)), groupBox2, SLOT(setDisabled(bool)));

lyuts
9th March 2010, 07:48
Yes, Lykurg, you are right. How could i miss such an obviuos thing.

jaca
9th March 2010, 19:38
Thanks guys! The help of all was very important.