QT基础:QT 定时器学习
定时器在编程中经常要用到,有必要学习一下,记记笔记!
Qt中定时器的使用有两种方法,一种是使用QObject类提供的定时器,还有一种就是使用QTimer类。
1、QObject中的定时器的使用,需要用到三个函数
int QObject::startTimer ( int interval ) ; // 开启定时器并设定间隔,返回定时器ID
void QObject::timerEvent ( QTimerEvent * event ); // 定时器到时处理函数
void QObject::killTimer ( int id ); // 关闭定时器
2、使用QTimer定时器类(可以使用信号与槽)
QTimer *timer = new QTimer(this); // 设置定时器
connect(timer, SIGNAL(timeout()), this, SLOT(onTimeout())); // 连接定时器到时槽函数
void QTimer::start ( int msec ); // 开启定时器并设定间隔
void QTimer::stop(); // 关闭定时器
关于定时器精度:
int QObject::startTimer(int interval, Qt::TimerType timerType = Qt::CoarseTimer);
void QTimer::setTimerType(Qt::TimerType atype);
Qt Assitant中的原文如下:
enum Qt::TimerType
The timer type indicates how accurate a timer can be.
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
#ifndef QTIMERDISPLAY_H
#define QTIMERDISPLAY_H #include <QObject> class QTimerDisplay : public QObject protected: signals: public slots: private: #endif // QTIMERDISPLAY_H |
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
#include "qtimerdisplay.h"
) QTimerDisplay::QTimerDisplay(QObject *parent) : QObject(parent) // ![0] // ![1] |
最新文章
- iOS chart 图表完美解决方案 基于swift
- js跨域那些事
- 《CDN技术详解》 - CDN知多少?
- Unity3d 枚举某个目录下所有资源
- python mysql desc
- C语言 百炼成钢17
- VBS基础篇 - 过程(sub 与 Function)
- Arrays类的十大用法
- 使用HTTP协下载文件
- DownloadProvider调试
- 自己主动生成材质Material(Unity3D开发之十九)
- APP设计规范大全
- CSS3 布局
- linux下用script和scriptreplay对命令行操作录像
- TJOI2015 day1解题报告
- [解读REST] 5.Web的需求 &; 推导REST
- vscode编辑器自动生成.vue文件
- python基础之 编码进阶,文件操作和深浅copy
- openstack网络
- elasticsearch6.7 05. Document APIs(10)Reindex API