qtimer类

来源:互联网 发布:淘宝质量好的男鞋店 编辑:程序博客网 时间:2024/05/29 14:48

qtimer的两种使用方法:

1.定义qtimer ,绑定timeout信号,调用taart发射信号

QTimer *timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), this, SLOT(update()));
    timer->start(1000);

2.设置setSingleShot(true),调用静态函数,这时定时器只调用一次,

QTimer::singleShot(200, this, SLOT(updateCaption()));



类的解读::

1.属性

active : const bool:::如果定时器正在运行为true,其他为false

singleShot::  发射一次信号设为true,定时器只跑一次

timerType : Qt::TimerType::这个属性保持定时器准确性,,默认属性为Qt::CoarseTimer::粗糙定时器,%5误差,Qt::PreciseTimer精确定时器

interval::定时器间隔, timerId()可以用来设置

remainingTime::剩余时间,初始化为-1,启动后直到为0


2.公有函数

QTimer::QTimer(QObject * parent = 0)构造函数


void QTimer::singleShot(int msec, const QObject * receiver, const char * member)静态函数

只需要调用,不创建对象,和绑定信号


void QTimer::singleShot(int msec, Qt::TimerType timerType, const QObject * receiver, const char * member)静态函数


void QTimer::singleShot(int msec, const QObject * receiver, PointerToMemberFunction method)静态函数


void QTimer::singleShot(int msec, Qt::TimerType timerType, const QObject * receiver, PointerToMemberFunction method)静态函数


void QTimer::singleShot(int msec, Functor functor)静态函数


void QTimer::singleShot(int msec, Qt::TimerType timerType, Functor functor)静态函数


void QTimer::singleShot(int msec, const QObject * context, Functor functor)静态函数


void QTimer::singleShot(int msec, Qt::TimerType timerType, const QObject * context, Functor functor)静态函数


void QTimer::start(int msec)槽函数

如果singleShot设为true,定时器只走一次


void QTimer::start()


void QTimer::stop()停止槽


void QTimer::timerEvent(QTimerEvent * e)事件


int QTimer::timerId() const返回id,如果正在运行返回-1
























0 0
原创粉丝点击