I'm trying to understand how to use signals to when one QCheckBox
be checked it uncheck all other checkboxes present in the same QGroupBox
class GroupBox : public QGroupBox
{
public:
GroupBox(QWidget *parent = nullptr) : QGroupBox(parent)
{
}
public slots:
void uncheck();
};
class CheckBox : public QCheckBox
{
public:
CheckBox(QWidget *parent = nullptr) : QCheckBox(parent)
{
connect(this, SIGNAL(checked()), this, SLOT(checked()));
}
public slots:
void checked()
{
qDebug() << "checked";
}
};
When I click on one of the checkboxes it didn't go to the function checked()
.
CodePudding user response:
QCheckBox inherits from QAbstractButton
You should use clicked or stateChanged signal instead of checked.
e.p.
connect(this, SIGNAL(stateChanged(int)), this, SLOT(checked(int)));
Btw; if using a modern Qt version, you should ditch the SIGNAL
and SLOTS
macros and instead use the new connect()
syntax that's checked at compile time.
Refer: New Signal Slot Syntax
e.p.
connect(this, &QCheckBox::clicked, this, &CheckBox::checked);