已解决:错在函数应为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();
}