您的位置:首页 > 编程语言 > Qt开发

QT学习之Timer的用法

2010-10-21 13:34 330 查看
QTimer的用法比较简单,看官方提供的使用例:

QTimer *timer = new QTimer(this);

connect(timer, SIGNAL(timeout()), this, SLOT(update()));

timer->start(1000);

每秒超时调用this->update()。

QT也提供了另外一个类:QBasicTimer,其用法例:

#include <QCoreApplication>
#include <QBasicTimer>
#include <QtCore/QDebug>

class MyClass:public QObject
{
public:
MyClass(){};

protected:
void timerEvent( QTimerEvent *event ){
qDebug() << "Time out timer id" << event->timerId();
}

};

int main( int argc, char *argv[] )
{
QCoreApplication app( argc, argv );
MyClass *mc = new MyClass();
QBasicTimer  bt;
bt.start( 120 * 1000, mc );

return app.exec();

}

发生超时事件的时候,会调用的mc->timerEvent(),而没有timerout()信号。

在WebKit的分析中有碰到QBasicTimer的使用。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  timer qt signal webkit bt