Qt 定时器

毫秒级定时器

#include <QTimerEvent>

public:
    void  handleTimeout();  //超时处理函数
    virtual void timerEvent(QTimerEvent *event);

private:
    int timerID;
#define TIMER_TIMEOUT   (5*1000)

timerID = this->startTimer(TIMER_TIMEOUT);
void timerEvent(QTimerEvent *event)
{
    if(event->timerId() == timerID){
        handleTimeout();
    }
}

void handleTimeout()
{
    qDebug() << "handleTimeout here\n";
    killTimer(timerID);
}
posted @ 2018-08-15 13:32  thomas_blog  阅读(169)  评论(0编辑  收藏  举报