kobe
1
#include<QApplication>
#include<QHBoxLayout>
#include<QSpinBox>
#include<QSlider>
int main(int argc,char* argv[])
{
QApplication app(argc,argv); //创建app的构造函数
QWidget* window = new QWidget; //new一个window
window->setWindowTitle("Set the value"); //设置caption
QSpinBox* spinbox = new QSpinBox; //new一个spinbox
QSlider* slider = new QSlider(Qt::Horizontal); //new一个slider
spinbox->setRange(0,150); //设置范围,->符号
slider->setRange(0,150);
QObject::connect(spinbox,SIGNAL(valueChanged(int)),slider,SLOT(setValue(int)));
QObject::connect(slider,SIGNAL(valueChanged(int)),spinbox,SLOT(setValue(int)));
//信号和槽,(发送者,信号,接收者,槽).第一个是spinbox发送给slider的
//第二个是slider发送给spinbox的
spinbox->setValue(28);
//QHBoxLayout是布局管理器,即在水平方向上排列窗口部件
QHBoxLayout* layout = new QHBoxLayout;
layout->addWidget(spinbox);
layout->addWidget(slider);
window->setLayout(layout);
window->show(); //窗体显示
return app.exec();
}