[mythtv] Advice on inter-thread communication and QT

Isaac Richards ijr at po.cwru.edu
Sun Oct 3 22:27:53 UTC 2004


On Sunday 03 October 2004 05:26 pm, Paul Volkaerts wrote:
> Hi;
>
> I am in the process of reworking the webcam code in MythPhone to make it
> run as a separate thread instead of in the GUI thread since it can block if
> there are no frames available.
>
> So I have a thread which fills buffers with frames from the webcam
> asynchronously say every 100ms. Is there a decent mechanism for this thread
> to cause the GUI thread to wake up and process an event?
>
> Currently I have a timer running every 100ms in the GUI thread which polls
> to see if there are webcam frames ready; but I really hate that kind of
> approach. Ideally I'd like the equivelant of "emit" but one that causes the
> callback to be called within the GUI thread instead of the calling thread
> (which I don't believe is the case, right?).

Check out the lirc code in libmyth/lirc* and mythdialogs.cpp - it does just 
what you want with a custom event and QApplication::postEvent().  
qapp::postEvent() is threadsafe, and just adds the event to the event queue, 
which'll then automatically wake up the gui thread and process the event.

Isaac


More information about the mythtv-dev mailing list