nutario
nutario

Reputation: 793

Event handler in Qt with multithread

Does any one know how the event handler manages the posted events?

In my app i have two threads (guiThread and computationThread). After an exception is thrown I call postEvent(..) to an existing dialog. The Qt-Event-Handler holds this one back until the dialog is closed.


Sorry my question is a bit cloudy. I will write it more exactly, if I have time left. I found a work around. But for me the problem is still interesting.

Upvotes: 1

Views: 4340

Answers (3)

Jérôme
Jérôme

Reputation: 27027

As mentionned in the Qt documentation about QCoreApplication::postEvent :

When control returns to the main event loop, all events that are stored in the queue will be sent using the notify() function.

...which explains why the Qt Event Handler holds the event until the dialog is closed.

If I understand correctly what you want to do, I would try using sendEvent.

Upvotes: 2

As others already wrote, I believe this behavior is caused by the fact that the dialog starts its own event loop.

If you use Qt4, you can try using queued signal/slot connections as an alternative to posting events.

Upvotes: 0

Caleb Huitt - cjhuitt
Caleb Huitt - cjhuitt

Reputation: 14941

I'm guessing that the dialog you created is modal, which would mean that it is running its own event loop. No events posted to the general guiThread will be processed until all modal event loops are exited.

Alternately, if you need the dialog to both be modal and know about the event, you could post the event directly to the dialog. You'll need to figure out how to handle pointers in a shared manner, but if nothing complicated is going on, you might be able to use the QApplication::activeWindow() function.

Upvotes: 1

Related Questions