PDA

View Full Version : QGroupBox and signal clicked(bool)



codebehind
30th August 2008, 12:51
I have a GUI done with designer (qt4)

it has a groupbox: theGroup
it has some radiobuttons: radio0, radio1, radio2;
it has a listwidget: monitor

then i've created a class MyClass which is derived from the gui.

I try to create a connection:

void theGroup::on_theGroup_clecked(bool )
{
qDebug("done.");
}

the result is that there is no msg on the console.
Then i tried to connect the radiobutton signal with a slot i've created and it works fine. I am lost.

jpn
30th August 2008, 13:04
QGroupBox emits clicked() signal in case it's a checkable group box and the check state of the group box changes. QGroupBox::clicked() is NOT emitted when an arbitrary checkbox/radiobutton/anything else inside the group box changes its check state.

codebehind
30th August 2008, 13:08
Find the bug!

I haven't understand the documentation well.

This signal works when the check box is activated.
The question now is: is there a way to have just one connection for all radiobuttons signal clicked in the qgroupbox or i have to make a connection for each radiobutton siglan?

jpn
30th August 2008, 13:12
See QButtonGroup.

codebehind
30th August 2008, 16:26
it is working! one way...

QGroupButton *myGroup;
in the constructor I've make a connection

connect(myGroup, SIGNAL(buttonClicked(QAbstractButton*)), this, SLOT(mySlot()));
and it works fine
i tried the qt4 way:

void on_myGroup_buttonClicked( QAbstractButton * button );

and i get this error at runtime:

QMetaObject::connectSlotsByName: No matching signal for on_myGroup_buttonClicked(QAbstractButton*)

jacek
30th August 2008, 17:20
QMetaObject matches QObject names --- it cannot see variables. Use QObject::setName().

codebehind
30th August 2008, 18:21
i've done it. the function is QObject::setObjectName() (http://doc.trolltech.com/4.4/qobject.html#objectName-prop).

the next problem is that I've set the name in the constructor but the signal - slot connection it has been already done at this point.

So i think that I should create a new class which is derived from QButtonGroup and has a constructor with a chance to set a name.
or is there a better solution?

jacek
30th August 2008, 19:16
the next problem is that I've set the name in the constructor but the signal - slot connection it has been already done at this point.
QMetaObject::connectSlotsByName() is called by setupUi(), so you have to create your button group earlier.


or is there a better solution?
Just initialize it before invoking setupUi() or make the connection using QObject::connect().

codebehind
30th August 2008, 19:27
it works.
a little detail - if you make ui with the designer, then you shoul put setupUi() befor any calling of other objects
for example:
I've add some radiobuttons (created with the designer) to the QButtonGroup. If i add those radio buttons to the buttongroup befor calling setupUi() the result is Segmentation Fault.

jacek
30th August 2008, 21:09
If i add those radio buttons to the buttongroup befor calling setupUi() the result is Segmentation Fault.
That's because setupUi() creates all of the widgets from the .ui file. Before you invoke it you just have uninitialized pointers.