PDA

View Full Version : postEvent thread problem



jhamers
5th March 2008, 10:22
Hello,

I’m having a problem with posting events to the GUI thread of mainwindow.

This is my setup:
I have several pieces of hardware that signal events through an old-style callback function (each of them is living in his own thread).

This callback function does a
QApplication::postEvent(mainwindow, customevent);

In the customevent handler of the mainwindow I pop up a standard (blocking) messagebox. This works fine until I connect more than one device.

I would have expected the event loop of mainwindow to process the events in sequence, but it doesn’t. It looks like that for each postevent I do from the callback, a new event loop (or thread) is created.
My understanding was that the posted events would be added to the queue of the main event loop of the receiver you specify in the call to postevent.

Is there another way that I can post events to a receiver (from different threads) and be sure they will be handled in sequence?

Kind Regards,
Jeroen

jpn
5th March 2008, 10:36
Actually it's not an extra thread, but just a nested event loop. QMessageBox is a modal dialog which runs its own event loop. Once the message box is closed, execution returns to the "main" event loop. These both event loops are running in the same thread and all events gets processed meanwhile either event loop is running.