[Qt-interest] What is the use of QCoreApplication::processEvents()

Arnold Krille arnold at arnoldarts.de
Mon Apr 6 13:54:54 CEST 2009


Hi,

On Monday 06 April 2009 12:34:13 shariff wrote:
> Can any one explain me the exact use of
> void QCoreApplication::processEvents ( QEventLoop::ProcessEventsFlags flags
> = QEventLoop::AllEvents )

Sometimes you will want to do heavier work inside one of your functions like 
searching a big file or searching in the directory tree. When you do all that 
in one big step inside the main gui thread, the gui thread will be blocked 
during that time, so there will be no updates which results in no repaints if 
the window gets covered and uncovered but also no updates to for example 
progressbars to show the progress. There are several solutions for this with 
different difficulty: (sorted by difficulty, highest first)
1) Using a separate thread for your heavy work and send signals/events to the 
gui-thread.
2) Split up your one big loop into a slot that does just one step and 
reschedules itself in the event-loop either by a QTimer inside your object or 
by QTimer::singleShot(). This allows for your work-steps to be part of the 
normal event queue and the gui stays responsive.
3) Call QCoreApplication::process() every now and then to process events (like 
repainting and button-clicks) inside your heavy work function.

Personally I think that #2 is the cleanest solution unless your work is really 
big and can easily run parallel to the gui (so problems bigger than "just" 
searching inside a document) in which case you should to #1...

Have a nice day,

Arnold
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090406/cd7e94c3/attachment.bin 


More information about the Qt-interest-old mailing list