[Qt-interest] How Qt Event loop and Qthread mechanism works!

Thiago Macieira thiago.macieira at trolltech.com
Sat Jun 20 17:05:16 CEST 2009


Santhosh Y wrote:
>Hi,
>
>This mail is regarding the how the event loop will work in a GUI Thread
>(Main thread) and in the Worker Thread.
>
>Following is my understanding:
>
>   1. For a GUI project we create a QApplication and we say exec() to
>      start a event loop. This event loop maintains the list of event
>      and dispatches to the receivers depending on the priority.
>   2. When we create a thread by subclassing QThread , we can say exec()
>      on thread to start its own event loop. (OR) We can emit signals in
>      this subclass and we can catch it in the GUI thread for acting to
>      the call.
>   3. One can manually post events to any object in any thread at any
>      time using the thread-safe function QCoreApplication::postEvent
>      <qcoreapplication.html#postEvent>(). The events will automatically
>      be dispatched by the event loop of the thread where the object was
>      created.
>
>Is my understanding correct?  Can anybody suggest me how can I better
>understand the  Qt event loop structure.
>How the Qt infrastructure for this event loop works?

It seems to me your understanding is correct.

Just the "OR" in point #2 you should realise that it's also an "and", 
since you can do both. Threads running event loops can emit signals too.
-- 
Thiago Macieira - thiago.macieira (AT) nokia.com
  Senior Product Manager - Nokia, Qt Software
      Sandakerveien 116, NO-0402 Oslo, Norway
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090620/7903d1bf/attachment.bin 


More information about the Qt-interest-old mailing list