2

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?

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Matthias Pospiech
  • 3,130
  • 18
  • 55
  • 76
  • 2
    You could show how you define the slot: `on_buttonGroupFFTDimension_buttonClicked` – eyllanesc Jul 14 '17 at 14:16
  • 2
    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, try changing the name of your slot, run `make clean` and then `qmake`. – eyllanesc Jul 14 '17 at 14:19

1 Answers1

4

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.
eyllanesc
  • 235,170
  • 19
  • 170
  • 241