Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

如何在中使用Qt中的Qtimer

From Wiki
Jump to: navigation, search
Article Metadata

代码示例
兼容于
平台:
Symbian

文章
翻译:
hoolee
最后由 hamishwillee 在 11 Oct 2012 编辑


简介

QTimer的构造方法如下所示:

iTimer = new QTimer(this);

设置超时时间值,可以通过setInterval()函数设置毫秒数值即可。如果你需要一秒超时时间,可以设置如下:

iTimer->setInterval(1000);
iTimer->start();

或者在启动函数时一并设置,代码如下:

iTimer->start(1000);

可以通过如下方法调用stop函数来终止处理:

iTimer->stop();

当超时后,QTimer将会发出timeout()信号,这样你可以连接到你自己的处理接口:

QObject::connect(iTimer, SIGNAL(timeout()), this, SLOT(TimeOut()));

注意缺省时QTimer将会不停的生成超时信号,直至你主动停止。如果要QTimer超时仅为一次,你可以调用setSingleShot()函数设置true值处理。


Example project

File:QtEggAlarm.zip

This page was last modified on 11 October 2012, at 01:18.
236 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×