无法连接 doublespinbox valuechanged 信号

3 qt

我需要连接信号和插槽

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
}
Run Code Online (Sandbox Code Playgroud)

这里我得到以下错误:

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
Run Code Online (Sandbox Code Playgroud)

我在这里犯了什么错误?

G.M*_*.M. 5

QDoubleSpinBox::valueChanged超载,因此您需要手动解决它...

connect(ui->doubleSpinBox_vertical,
        QOverload<double>::of(&QDoubleSpinBox::valueChanged),
        this,
        &MainWindow::updateThreshold);
Run Code Online (Sandbox Code Playgroud)