Qt cross thread call

Posted by QLatvia on Stack Overflow See other posts from Stack Overflow or by QLatvia
Published on 2010-05-29T15:21:29Z Indexed on 2010/05/29 15:22 UTC
Read the original article Hit count: 280

Filed under:
|
|

I have a Qt/C++ application, with the usual GUI thread, and a network thread. The network thread is using an external library, which has its own select() based event loop... so the network thread isn't using Qt's event system.

At the moment, the network thread just emit()s signals when various events occur, such as a successful connection. I think this works okay, as the signals/slots mechanism posts the signals correctly for the GUI thread.

Now, I need for the network thread to be able to call the GUI thread to ask questions. For example, the network thread may require the GUI thread to request put up a dialog, to request a password.

Does anyone know a suitable mechanism for doing this?

My current best idea is to have the network thread wait using a QWaitCondition, after emitting an object (emit passwordRequestedEvent(passwordRequest);. The passwordRequest object would have a handle on the particular QWaitCondition, and so can signal it when a decision has been made..

Is this sort of thing sensible? or is there another option?

© Stack Overflow or respective owner

Related posts about c++

Related posts about qt