已解決:錯在函式應為valueChanged()---------------------------------------------------------------------------------------------------------------------初學qt, 運行后報錯:no such signal QSpinBox::valueChange(int)視窗是可以顯示的,只是兩個object間沒法完成資料通信。以下是原始碼,先謝謝了!#include "stdafx.h"#include <Qapplication>#include <QHboxLayout>#include <QSlider>#include <QSpinBox>int main(int argc, char*argv[]){ QApplication app(argc, argv); QWidget *window = new QWidget; window->setWindowTitle("Enter Your Age"); QSpinBox *spinBox=new QSpinBox; QSlider *slider = new QSlider(Qt::Horizontal); spinBox->setRange(0, 130); slider->setRange(0, 130); QObject::connect(spinBox, SIGNAL(valueChange(int)), slider, SLOT(setValue(int))); QObject::connect(slider, SIGNAL(valueChange(int)), spinBox, SLOT(setValue(int))); spinBox->setValue(35); QHBoxLayout *layout = new QHBoxLayout; layout->addWidget(slider); layout->addWidget(spinBox); window->setLayout(layout); window->show(); return app.exec();}
uj5u.com熱心網友回復:
出錯資訊很明確,QSpinBox 確實沒有這個信號。uj5u.com熱心網友回復:
額,抄書 抄錯了!!!uj5u.com熱心網友回復:
人如其名啊,哈哈,開玩笑!uj5u.com熱心網友回復:
問題原因是函式 valueChanged 有兩個形態:QSpinBox::valueChanged(int) 和 QSpinBox::valueChanged(QString),編譯器不知道要使用哪個函式解決辦法也可以是https://blog.csdn.net/dee53994040/article/details/102178933及https://blog.csdn.net/weixin_42607149/article/details/88682387轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/284670.html
標籤:其他技術討論專區
