qt 第一步实现 联动

标签:
杂谈 |
分类: qt |
代码如下
#include <QApplication>
#include <QSpinBox>
#include <QHBoxLayout>
#include <QLabel>
int main(int argc, char *argv[])
{
QString qsum;
QApplication app(argc,argv);
QWidget *window = new QWidget;
window->setWindowTitle("just change at the same time");
QSpinBox *spinBox1 = new QSpinBox;
spinBox1->setRange(0,39);
QLabel *label1 = new QLabel;
label1->setText("hello");
QLabel *label2 = new QLabel;
label2->setText("hello");
QSpinBox *spinBox3 = new QSpinBox;
spinBox3->setRange(0,39);
int sum = spinBox1->value() + spinBox3->value();
qsum = (QString) sum;
QObject::connect(spinBox1, SIGNAL(valueChanged(QString)), label1, SLOT(setText(QString)));
QObject::connect(spinBox1, SIGNAL(valueChanged(int)), label2, SLOT( setNum(int)));
//QObject::connect(spinBox1, SIGNAL(valueChanged(int)), spinBox3, SLOT(setValue(int)));
spinBox1->setValue(4);
QHBoxLayout *layout = new QHBoxLayout;
layout->addWidget(spinBox1);
layout->addWidget(label1);
layout->addWidget(label2);
layout->addWidget(spinBox3);
window->setLayout(layout);
window->show();
return app.exec();
}
运行截图如下:
http://s4/middle/500bd63ctc796b28cbfb3&690第一步实现联动" TITLE="qt 第一步实现 联动" />