PDA

View Full Version : MainWindow update during computations



Gizmho
11th July 2006, 18:06
Hi all,

my Qt application is running under Windows XP and I am using a second console window for some output text. Whenever I click on that console window during some computation in the app, the MainWindow is not updated any more (no resize, no redrawing, ...). My whole application is running in a single thread. Is there a way to keep the MainWindow alive during longer computations (including graphical updates).

I tried QApplication::flush and all kind of update and repaint calls at different places in the code.

Thanks a lot for any hint!

jpn
11th July 2006, 18:16
You can call QApplication::processEvents() once in a while inside a long lasting loop to make your application responsible.

Gizmho
12th July 2006, 09:32
Perfect. Exactely what I needed, thx.

Does the call processEvents() slow down the application?

yogeshm02
12th July 2006, 17:17
See qt doc /usr/local/qt/doc/html/eventsandfilters.html (Change path accordingly for your installation) or
Search for "Event filters" (in qt assistant) and select "Qt 4.1 Events and Event Filters"

You will get all what you need. Happy reading. ;)

gfunk
13th July 2006, 19:09
Does the call processEvents() slow down the application?

Probably just the price of a function call, multiplied by how many times you need to call it, as well as the cost of processing the events. But that's just the price of having your application "feel" like it's doing multitasking and being responsive. You can't get things for free. For the most part, the performance drop should be negligible.

aMan
13th July 2006, 19:39
how does this handle the following thing:



computing very much A
break -> processEvents()
compute something
compute something
compute very much B
continue with A
computing very much A
..



will A continue only after B is finished?
so when i call A in B, then i'll get a recursion?

regards..
aman..

gfunk
13th July 2006, 19:56
Yes, according to the docs, processEvents() processes all pending events before returning - all this work is done in the same thread. So, if function A() calls processEvents(), and one of the event handlers (perhaps B()) then calls A() again, there might be some recursion. I don't think it would be infinite recursion; the event being processed must be removed from the list of pending events before getting processed, and it looks like Qt follows this at least in Windows (in qeventdispatcher_win.cpp):
msg = d->queuedUserInputEvents.takeFirst();

The funny result is that events might be processed in reverse order as it finishes its recursion; but the processing should go on as the pending event list is whittled away.

aMan
13th July 2006, 20:10
thank you, that helped me understand the system..

regards..
aman..