QT学习之信号与槽(二) QSlider 与QSpinBox互动

//信号和槽的学习二 QSlider 与 QSpinBox的互相发送信号(互动)
//槽函数
//点击按钮关闭标签,要建立信号和槽的关系
//发送信号,由要操作的槽函数接收并处理
#include 
#include 
#include 
#include 

int main(int argc,char** argv)
{
    QApplication app(argc,argv);

    QDialog parent;
    parent.resize(500,500);

    //创建选值框
    QSpinBox spinbox(&parent);
    spinbox.move(120,200);
    //选值框默认值为0-99,重设置为0-200
    spinbox.setRange(0,200);

    //创建水平滑块
    QSlider slider(Qt::Horizontal,&parent);
    slider.move(10,200);
    slider.setRange(0,200);

    QObject::connect(&spinbox,SIGNAL(valueChanged(int)),
                     &slider,SLOT(setValue(int)));
    QObject::connect(&slider,SIGNAL(valueChanged(int)),
                     &spinbox,SLOT(setValue(int)));

    //显示父窗口及其控件
    parent.show();

    return app.exec();
}

你可能感兴趣的:(QT学习,windows,c++,算法)