- #include<QtGui>
- int main(int argc,char* argv[])
- {
- QApplication app(argc,argv);
- QLabel *pLabel=new QLabel;
- QSlider *pSlider=new QSlider(Qt::Horizontal);
- QSpinBox *pSbin=new QSpinBox;
- QDialog *dialog=new QDialog;
- QVBoxLayout *vboxlayout=new QVBoxLayout;
- pSbin->setValue(50);
- pSlider->setValue(50);
- pLabel->setNum(50);
- vboxlayout->addWidget(pLabel);
- vboxlayout->addWidget(pSbin);
- vboxlayout->addWidget(pSlider);
- dialog->setLayout(vboxlayout);
- QObject::connect(pSlider,SIGNAL(valueChanged(int)),pSbin,SLOT(setValue(int)));//关联信号与槽函数
- QObject::connect(pSlider,SIGNAL(valueChanged(int)),pLabel,SLOT(setNum(int)));
- QObject::connect(pSbin,SIGNAL(valueChanged(int)),pSlider,SLOT(setValue(int)));
- dialog->show();
- return app.exec();
- }
转载于:https://blog.51cto.com/zero66/1149227