1

I would like to use the new signal slot syntax, as in this example

connect(sender, &Sender::valueChanged, 
        receiver, &Receiver::updateValue );

I implemented this as

connect(ui->doubleSpinBoxExposure, &QDoubleSpinBox::valueChanged,
        this, &WidgetCameraParameter::on_doubleSpinBoxExposure_valueChanged );

This however throws this error

error: no matching function for call to 'WidgetCameraParameter::connect(QDoubleSpinBox*&, , WidgetCameraParameter*, void (WidgetCameraParameter::*)(double))' this, &WidgetCameraParameter::on_doubleSpinBoxExposure_valueChanged );

The classic connect works

connect(ui->doubleSpinBoxExposure, SIGNAL(valueChanged(double)),
        this, SLOT(on_doubleSpinBoxExposure_valueChanged(double)));

The connecSlotsByName also does not work

QMetaObject::connectSlotsByName: No matching signal for on_doubleSpinBoxExposure_valueChanged(double) [Warning] 07-09-2018, 08:18; Thread: 0xcfdea0; ;

I would like to understand the reason for this error and warning messages.

Matthias Pospiech
  • 3,130
  • 18
  • 55
  • 76
  • use `connect(ui->doubleSpinBoxExposure, QOverload::of(&QDoubleSpinBox::valueChanged), this, &WidgetCameraParameter::on_doubleSpinBoxExposure_valueChanged);` – eyllanesc Sep 07 '18 at 07:44
  • 1
    There are 2 signals with the same name: `valueChanged(double d)` `void valueChanged(const QString &text)`, therefore the compiler can not decide. – eyllanesc Sep 07 '18 at 07:47
  • Indeed a duplicate. The reasons for the error, means for me that I will rather stick to the old syntax. Still missing is the auto connect warning. – Matthias Pospiech Sep 07 '18 at 07:48
  • 2
    mmm, the old syntax can fail and I will not warn you, the new syntax instead will point out the errors, so I prefer to be yelled at that it is failing to remain silent without telling me the errors. ;) – eyllanesc Sep 07 '18 at 07:50
  • If you check the docs it indicates the correct use: http://doc.qt.io/qt-5/qdoublespinbox.html#valueChanged – eyllanesc Sep 07 '18 at 07:51
  • 5
    @MatthiasPospiech I just want to echo what eyllanesc said, you would rather fail during runtime compared to fail during compile time... Fail at compile time is one of the many strengths of C++ that sets it apart from other languages :P – CJCombrink Sep 07 '18 at 08:01

0 Answers0