QT step2

#include <QApplication>
2 #include <QHBoxLayout>
3 #include <QSlider>
4 #include <QSpinBox>
5 int main(int argc, char *argv[])
6 {
7 QApplication app(argc, argv);
8 QWidget *window = new QWidget;

9 window->setWindowTitle("Enter Your Age");//set up the QWidget that will serve as the application's main window.

10 QSpinBox *spinBox = new QSpinBox;
11 QSlider *slider = new QSlider(Qt::Horizontal);
12 spinBox->setRange(0, 130);
13 slider->setRange(0, 130);//create a QSpinBox and a QSlider,

/*these widgets should have window as their parent, but it isn't necessary here because the layout system will figure this out by itself and automatically set the parent of the spin box and the slider*/


14 QObject::connect(spinBox, SIGNAL(valueChanged(int)),
15 slider, SLOT(setValue(int)));

16 QObject::connect(slider, SIGNAL(valueChanged(int)),
17 spinBox, SLOT(setValue(int)));//A a =new A...; B b = new B...; (a, signal, b, action); (b,signal,a,action)
18 spinBox->setValue(35);

/*QSpinBox emits the valueChanged(int) signal with an int argument of 35.QSlider's setValue(int) slot,sets the slider value to 35.The slider then emits the valueChanged(int) signal because its own value changed, triggering the spin box's setValue(int) slot. But at this point, setValue(int) doesn't emit any signal, since the spin box value is already 35. This prevents infinite recursion.*/


19 QHBoxLayout *layout = new QHBoxLayout;

/*A layout manager is an object that sets the size and position of the widgets that lie under its responsibility.Qt has three main layout manager classes:QHBoxLayout,QVBoxLayout,QGridLayout lays out widgets in a grid.*/

20 layout->addWidget(spinBox);
21 layout->addWidget(slider);
22 window->setLayout(layout);//installs the layout manager on the window


23 window->show();
24 return app.exec();
25 }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值