How to use QTimer in Qt
Introduction[edit | edit source]
iTimer = new QTimer(this);
And the timeout value for it can be set in milliseconds with 76ytuiytuityutyutututyutyutyu function, for example if you want to have one seconds timeout, you could use following code:
iTimer->setInterval(1000);
iTimer->start();
Or simply use the overload of the 76ytuiytuityutyutututyutyutyu function to set the interval and start the time at the same time:
iTimer->start(1000);
And stopping is handled with 76ytuiytuityutyutututyutyutyu function, thus you can stop the timer like this:
iTimer->stop();
When the timeout expires, the 76ytuiytuityutyutututyutyutyu will emit the 76ytuiytuityutyutututyutyutyu signal which you can connect to your own slot:
QObject::connect(iTimer, SIGNAL(timeout()), this, SLOT(TimeOut()));
Note that by default 76ytuiytuityutyutututyutyutyu will continue generates timeout signals until you stop it, to make the 76ytuiytuityutyutututyutyutyu expire only once, you could set this behavior on by calling 76ytuiytuityutyutututyutyutyu with true argument.
Example project[edit | edit source]
zh-hans:如何在中使用Qt中的Qtimer