[Qt-interest] Does QCoreApplication::processEvents() update timers?
Girish Ramakrishnan
girish at forwardbias.in
Wed Apr 29 05:05:00 CEST 2009
Karol Krizka wrote:
> On Monday 27 April 2009 20:51:47 Girish Ramakrishnan wrote:
>> Karol Krizka wrote:
>>> Hi all,
>>>
>>> I am using a third party 3D engine to draw a scene in a QGLWidget. The
>>> scene is quite big, so it takes a while to load, so I want to show some
>>> kind of an animation while it loads. However, the engine is not thread
>>> safe, so I cannot do the loading in one thread and drawing in another.
>>> What I would like to do instead is to redrew the scene after each major
>>> component has been loaded. It will be a bit choppy, but better than
>>> nothing.
>>>
>>> I'm trying to accomplish this by having my drawing done inside a timer
>>> loop and call QApplication::processEvents(). Basically, I started a timer
>>> with QObject::startTimer() inside the QGLWidget and inside it I call
>>> updateGL(). I'm hoping that when I call processEvents(), it will call
>>> timerEvent() every while in order to trigger the redraw. However that
>>> does not happen. The timerEvent() is not called at all during the loading
>>> stage.
>>>
>>> So my question is, does QApplication::processEvents() also update any
>>> running timers?
>> Yes, your object will get timerEvent() if you do processEvents(). Maybe
>> you can show some code with which you are facing this problem?
>>
> Take the following example. It performs some long action (printing out a lot
> of numbers) that is started from the first timer event. This is similiar to
> what I'm doing, but instead of printing numbers I'm loading textures.
>
<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
More information about the Qt-interest-old
mailing list