Qt signal on buttongroup not connected

946 views Asked by At

I have a buttongroup defined with two radiobuttons

buttonGroupFFTDimension = new QButtonGroup(this);
buttonGroupFFTDimension->addButton(ui->radioButton1D, 1);
buttonGroupFFTDimension->addButton(ui->radioButton2D, 2);
buttonGroupFFTDimension->setExclusive(true);
ui->radioButton1D->setChecked(true);

The connect also compiles

connect(this->buttonGroupFFTDimension, static_cast<void(QButtonGroup::*)(int)>(&QButtonGroup::buttonClicked),
        this, &MainWindow::on_buttonGroupFFTDimension_buttonClicked);

but it throws and error at runtime

QMetaObject::connectSlotsByName: No matching signal for on_buttonGroupFFTDimension_buttonClicked(int)

I admit that I am not familiar with the new connect syntax, but also do not see the obvious error. What is wrong?

1

There are 1 answers

0
eyllanesc On BEST ANSWER

The message shown is because you are using Qt Designer and it uses the connectSlotsByName method to connect various elements, it recognizes the format on_somesender_somesignal, and in your case matches your slot.

  • First solution: It iss unnecessary to use the connect function, this will automatically do it. Also I think that the slot does not have as parameter the type int that requires.

In your case the slot should be as follows:

private  slots:
    void on_buttonGroupFFTDimension_buttonClicked (int val);
  • Another possible solution is to rename the slot, after that you run make clean and qmake.