c++qtqt5qt-signalsqt-slot

Qt signal on buttongroup not connected


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?


Solution

  • 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.

    In your case the slot should be as follows:

    private  slots:
        void on_buttonGroupFFTDimension_buttonClicked (int val);