cant connect doublespinbox valuechanged signal

Viewed 227

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 Answers

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

connect(ui->doubleSpinBox_vertical,
        QOverload<double>::of(&QDoubleSpinBox::valueChanged),
        this,
        &MainWindow::updateThreshold);
Related