3

I need to connect a signal and slot

connect(ui->doubleSpinBox_vertical, &QDoubleSpinBox::valueChanged, this, &MainWindow::updateThreshold);


void MainWindow::updateThreshold()
{
    const double threshold = ui->spinBox->value();
    int labelY = qRound(threshold / ui->progressBar->maximum() * ui->progressBar->height());
    ui->label_2->move(0, ui->progressBar->height() - labelY); // y is inverted
}

Here I get following error:

mainwindow.cpp:14:5: error: no matching member function for call to 'connect'
qobject.h:208:36: note: candidate function not viable: no overload of 'valueChanged' matching 'const char *' for 2nd argument
qobject.h:211:36: note: candidate function not viable: no overload of 'valueChanged' matching 'const QMetaMethod' for 2nd argument
qobject.h:463:41: note: candidate function not viable: no overload of 'valueChanged' matching 'const char *' for 2nd argument
qobject.h:228:43: note: candidate template ignored: couldn't infer template argument 'Func1'
qobject.h:269:13: note: candidate template ignored: couldn't infer template argument 'Func1'
qobject.h:308:13: note: candidate template ignored: couldn't infer template argument 'Func1'
qobject.h:260:13: note: candidate function template not viable: requires 3 arguments, but 4 were provided
qobject.h:300:13: note: candidate function template not viable: requires 3 arguments, but 4 were provided

What mistake I'm doing here?

1 Answers1

5

QDoubleSpinBox::valueChanged is overloaded so you need to resolve it manually...

connect(ui->doubleSpinBox_vertical,
        QOverload<double>::of(&QDoubleSpinBox::valueChanged),
        this,
        &MainWindow::updateThreshold);
G.M.
  • 12,232
  • 2
  • 15
  • 18
  • Thansk for your response. I now get an unresolved ext symbol: –  Aug 24 '20 at 13:16
  • moc_mainwindow.obj:-1: error: LNK2019: unresolved external symbol "private: void __cdecl MainWindow::on_doubleSpinBox_vertical_valueChanged(class QString const &)" (?on_doubleSpinBox_vertical_valueChanged@MainWindow@@AEAAXAEBVQString@@@Z) referenced in function "private: static void __cdecl MainWindow::qt_static_metacall(class QObject *,enum QMetaObject::Call,int,void * *)" (?qt_static_metacall@MainWindow@@CAXPEAVQObject@@W4Call@QMetaObject@@HPEAPEAX@Z) –  Aug 24 '20 at 13:17
  • 1
    That's a different issue. Qt Designer will create automatic connections to slots named in a certain way such as `on_doubleSpinBox_vertical_valueChanged`. Have a look at [this post](https://stackoverflow.com/questions/28987152/qt-creator-change-code-generating-template-for-slots). – G.M. Aug 24 '20 at 13:37