简单signal的使用

480阅读 0评论2014-12-09 644924073
分类:LINUX

http://blog.chinaunix.net/photo/116111_101004123939.gif
上面是效果图,拖动滚动条时,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
下载: 下载
上一篇:实现简单的notepad功能
下一篇:从接收套接字中提取对方的ip地址和端口信息