QT定时器基本用法
来源:互联网 发布:vb语言和java 编辑:程序博客网 时间:2024/05/18 17:04
在Qt中有很多需要以一定的频率刷新显示的需求,这时就要用到定时器,这个定时器就是在超时的时候发送信号,然后收到信号后做一些处理即可;然后定时器会重启,继续以之前设定的时间,开始倒计时。以下为一个测试代码:
#ifndef TEST_H
#define TEST_H
#include <QWidget>
#include <QLabel>
#include <QTimer>
class Mywidget: public QWidget
{
Q_OBJECT
public:
Mywidget(QWidget *parent = 0);
~Mywidget();
public slots:
void RefreshRate();
private:
QLabel sent_rate_name;
QLabel recv_rate_name;
QLabel sent_rate;
QLabel recv_rate;
QTimer *mytimer;
void modulesShow();
};
#endif //
#include "test.h"
//View
Mywidget::Mywidget(QWidget *parent) :
QWidget(parent)
{
//set parent
sent_rate_name.setParent(this);
sent_rate.setParent(this);
recv_rate_name.setParent(this);
recv_rate.setParent(this);
//set text
recv_rate_name.setGeometry(QRect(50, 225, 70, 20));
sent_rate_name.setGeometry(QRect(210, 225, 70, 20));
recv_rate.setGeometry(QRect(130, 225, 70, 20));
sent_rate.setGeometry(QRect(300, 225, 70, 20));
sent_rate_name.setText("上传速度:");
recv_rate_name.setText("下载速度:");
mytimer = new QTimer(this);
connect(mytimer, SIGNAL(timeout()), this, SLOT(RefreshRate())); //定时器处理函数
mytimer->start(1000);//开始定时,并设置定时时间
modulesShow();
}
Mywidget::~Mywidget()
{
}
void Mywidget::modulesShow()
{
sent_rate_name.show();
recv_rate_name.show();
sent_rate.show();
recv_rate.show();
}
void Mywidget::RefreshRate()
{
sent_rate.setText(format_show(0,global_sent));
recv_rate.setText(format_show(0,global_rcvd));
}
- QT定时器基本用法
- QT定时器QTimer用法
- Qt中两种定时器用法
- Qt中两种定时器用法
- QT定时器的用法
- Qt中两种定时器用法
- Qt中两种定时器用法
- Qt中两种定时器用法
- 多线程 : 定时器基本用法
- QT中定时器的用法
- qt中定时器的用法
- Qt定时器两种用法
- java定时器的基本用法
- qt 基本用法
- qt qtableview基本用法
- qt qtableview基本用法
- QT tableWidget基本用法
- QT里定时器QTimer的用法
- 网页性能之Html Css Javascript
- 上传弹出窗(仿百度云)V_1(学习)
- (10.1.3)扁平化设计五大原则
- 乾坤合一~Linux设备驱动之块设备驱动
- Spring MVC 简介
- QT定时器基本用法
- OpenSessionInViewFilter源码分析
- Linux学习篇之---Configure script(配置脚本)
- 进入OpenCV内部源码调试
- [软件安装] libsvm for matlabR2012b on Mac OSX 10.9
- 关于CSS[几乎]没人知道的3件事
- [leetcode]Add and Search Word - Data structure design
- 《 机器学习实战》(Machine Learning in Action) 一书 中的错误之处(内容、代码)
- 关于hibernate 更新后立即查询数据,取到的是更新之前的数据的问题