[Qt-interest] Does QCoreApplication::processEvents() update timers?
Bill KING
bill.king at trolltech.com
Wed Apr 29 05:18:56 CEST 2009
Girish Ramakrishnan wrote:
> <part of example snipped>
>
>
>> void TimerApp::timerEvent(QTimerEvent *event)
>> {
>> if(firstGo)
>> {
>> performLongAction();
>> firstGo=false;
>> }
>> qDebug() << "Timer Event";
>> }
>>
>> void TimerApp::performLongAction()
>> {
>> for(int i=0;i<1000000;i++)
>> {
>> qDebug() << i;
>> QCoreApplication::processEvents();
>> }
>> }
>>
>
> You are expecting new timer events to arrive when you are not finished
> with the first timer event's handling. Qt won't let you recurse through
> a timer event (I think this is platform specific), which is the reason
> you are not seeing more timer events.
>
> (There are many ways to achieve what you want - For example, just break
> up your timer event task and enter app.exec(). Just make sure that the
> timer event task is small enough).
>
> Girish
>
>
Further to girish's information, if on your first run through the timer,
you use QMetaObject::invokeMethod with Qt::QueuedConnection, then on the
next round of the event loop, it'll execute your longAction next round
through the event queue, and return from the timerEvent quickly, thereby
allowing subsequent timerEvents to fire off. Also, I'd put firstGo=false
before performing the long action, otherwise, every single timer event
will try and perform the long action until it's completed. Not your
intended functionality.
--
Bill King, Software Engineer
Qt Software, Nokia Pty Ltd
Brisbane Office
More information about the Qt-interest-old
mailing list