MainWindow update during computations
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!
Re: MainWindow update during computations
You can call QApplication::processEvents() once in a while inside a long lasting loop to make your application responsible.
Re: MainWindow update during computations
Perfect. Exactely what I needed, thx.
Does the call processEvents() slow down the application?
Re: MainWindow update during computations
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. ;)
Re: MainWindow update during computations
Quote:
Originally Posted by Gizmho
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.
Re: MainWindow update during computations
how does this handle the following thing:
Code:
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..
Re: MainWindow update during computations
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.
Re: MainWindow update during computations
thank you, that helped me understand the system..
regards..
aman..