QGroupBox and signal clicked(bool)
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:
Code:
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.
Re: QGroupBox and signal clicked(bool)
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.
Re: QGroupBox and signal clicked(bool)
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?
Re: QGroupBox and signal clicked(bool)
Re: QGroupBox and signal clicked(bool)
it is working! one way...
Code:
QGroupButton *myGroup;
in the constructor I've make a connection
Code:
connect(myGroup,
SIGNAL(buttonClicked
(QAbstractButton*)),
this,
SLOT(mySlot
()));
and it works fine
i tried the qt4 way:
and i get this error at runtime:
Quote:
QMetaObject::connectSlotsByName: No matching signal for on_myGroup_buttonClicked(QAbstractButton*)
Re: QGroupBox and signal clicked(bool)
QMetaObject matches QObject names --- it cannot see variables. Use QObject::setName().
Re: QGroupBox and signal clicked(bool)
i've done it. the function is QObject::setObjectName().
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?
Re: QGroupBox and signal clicked(bool)
Quote:
Originally Posted by
codebehind
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.
Quote:
Originally Posted by
codebehind
or is there a better solution?
Just initialize it before invoking setupUi() or make the connection using QObject::connect().
Re: QGroupBox and signal clicked(bool)
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.
Re: QGroupBox and signal clicked(bool)
Quote:
Originally Posted by
codebehind
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.