加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

qt 第一步实现 联动

(2012-08-19 12:17:54)
标签:

杂谈

分类: 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 第一步实现 联动" />


0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有