[Qt-interest] Does QCoreApplication::processEvents() update timers?
Karol Krizka
kkrizka at gmail.com
Sun May 3 01:21:30 CEST 2009
On Tuesday 28 April 2009 20:18:56 Bill KING wrote:
> 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.
Ah, thank you. That fixed the problem.
> 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.
--
Cheers,
Karol Krizka
http://www.krizka.net
More information about the Qt-interest-old
mailing list