Chinaunix首页 | 论坛 | 博客

OS

  • 博客访问: 2228743
  • 博文数量: 691
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 2660
  • 用 户 组: 普通用户
  • 注册时间: 2014-04-05 12:49
个人简介

不浮躁

文章分类

全部博文(691)

文章存档

2019年(1)

2017年(12)

2016年(99)

2015年(207)

2014年(372)

分类: LINUX

2014-12-09 21:32:56

原文地址:简单signal的使用 作者:xutianxi

上面是效果图,拖动滚动条时,label上的数字会发生变化
 
 
代码实现如下:
Dialog.h文件代码
#ifndef DIALOG_H
#define DIALOG_H
#include
#include
#include
class Dialog:public QDialog
{
private:
    QLabel *label;
    QScrollBar *scrollbar;
public:
    Dialog(QWidget *parent = 0);
};
#endif // DIALOG_H

 
Dialog.cpp文件代码
#include "Dialog.h"
#include
Dialog::Dialog(QWidget *parent):QDialog(parent)
{
    label = new QLabel("0", this);
    label->setGeometry( 10, 10, 200, 300);
    scrollbar = new QScrollBar(this);
    scrollbar->setGeometry(200, 0, 20, 300);
    scrollbar->setRange(0, 300);
    QObject::connect(scrollbar, SIGNAL(valueChanged(int)),
                     label, SLOT(setNum(int)));
}
 
main.cpp代码:
#include
#include "Dialog.h"
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    Dialog d;
    d.show();
    return app.exec();
}
 
文件: signal.rar
大小: 153KB
下载: 下载
阅读(396) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~