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.

How to use QTimer in Qt

From Wiki
Jump to: navigation, search

Article Metadata
Code ExampleTested with
Devices(s): Symbian emulator
Platform(s): Qt
Keywords: QTimer
Created: james1980 (28 Dec 2008)
Last edited: hamishwillee (11 Oct 2012)


The construction of a QTimer can be done with following code:

iTimer = new QTimer(this);

And the timeout value for it can be set in milliseconds with setInterval() function, for example if you want to have one seconds timeout, you could use following code:


Or simply use the overload of the start() function to set the interval and start the time at the same time:


And stopping is handled with stop() function, thus you can stop the timer like this:


When the timeout expires, the QTimer will emit the timeout() signal which you can connect to your own slot:

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

Note that by default QTimer will continue generates timeout signals until you stop it, to make the QTimer expire only once, you could set this behavior on by calling setSingleShot with true argument.

Example project

This page was last modified on 11 October 2012, at 01:17.
500 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.