【问题标题】:cant connect doublespinbox valuechanged signal [duplicate]无法连接 qdoublespinbox valuechanged 信号 [重复]
【发布时间】:2020-12-13 03:05:46
【问题描述】:

我需要连接信号和插槽

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
}

这里出现以下错误:

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

我在这里犯了什么错误?

【问题讨论】:

    标签: qt


    【解决方案1】:

    QDoubleSpinBox::valueChanged 过载,需要手动解决...

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

    【讨论】:

    • 感谢您的回复。我现在得到一个未解析的分机符号:
    • moc_mainwindow.obj:-1: 错误: LNK2019: 无法解析的外部符号“private: void __cdecl MainWindow::on_doubleSpinBox_vertical_valueChanged(class QString const &)” (?on_doubleSpinBox_vertical_valueChanged@MainWindow@@AEAAXAEBVQString@@@Z ) 在函数“private: static void __cdecl MainWindow::qt_static_metacall(class QObject *,enum QMetaObject::Call,int,void * *)”中引用 (?qt_static_metacall@MainWindow@@CAXPEAVQObject@@W4Call@QMetaObject@@HPEAPEAX@Z )
    • 这是一个不同的问题。 Qt Designer 将创建以特定方式命名的插槽的自动连接,例如on_doubleSpinBox_vertical_valueChanged。看看this post
    猜你喜欢
    • 1970-01-01
    • 2018-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-02
    • 2012-02-06
    相关资源
    最近更新 更多