Qt分析:Qt中的两种定时器

QTimer类的定时器

QTimer类定时器是QObject类定时器的扩展版或者说升级版,因为它可以提供更多的功能。比如说,它支持单次触发和多次触发。

使用QTimer类定时器的步骤:

(1)创建一个QTimer定时器实例:QTimer *timer = new QTimer(this);
(2)连接超时信号与槽:connect(timer, SIGNAL(timeout()), this, SLOT(testFunc()));
(3)启动定时器start();
(4)适时关闭定时器:stop();
(5)删除定时器实例:delete timer;

公共函数:

int interval() const 获得定时器时间间隔

bool isActive() const 获得定时器激活状态

bool isSingleShot() const 获得单次触发使能状态

int remainingTime() const 获得距离触发定时器事件的剩余时间

void setInterval(int msec) 设置定时器时间间隔

void setSingleShot(bool singleShot) 设置使能/禁用单次触发

void setTimerType(Qt::TimerType atype) 设置定时器类型

int timerId() const 获得定时器标识符

Qt::TimerType timerType() const 获得定时器类型

公共槽函数:

void start(int msec) 启动定时时间间隔为msec毫秒的定时器
void start() 启动定时器
void stop() 暂停定时器

原文地址:https://www.cnblogs.com/renwei555/p/9555389.html