[Top] [All Lists]

Re: Pass execution of a fuction to a different QThread

Subject: Re: Pass execution of a fuction to a different QThread
From: Bo Thorsen
Date: Fri, 10 Mar 2006 13:43:49 +0100
Friday 10 March 2006 00:22 Darrell Blake wrote:
> Is it possible to pass the execution of a function to a different QThread?
> I have two classes in my application. One is an SDL and OpenGL window where
> I render my scene and do all the graphics stuff, the other is a QT GUI
> which has controls on it which can modify the OpenGL window (I know about
> the QT OpenGL widget but I have reasons for doing it with a seperate
> window). The QT GUI is running in the main thread and I've set up a QThread
> to run the OpenGL window in.
> I have set up an Observer pattern using the OpenGL window as the Observer
> and the QT GUI as the Subject and when I click an Update button on the QT
> GUI it notifies the OpenGL window of the update. Functions on the OpenGL
> window are being called from the QT GUI to update the view but some of
> these functions run OpenGL functions such as glGetString().
> The problem with this is that because of this setup the glGetString() (and
> other OpenGL functions) is running in the main thread and all of the OpenGL
> stuff was set up to run in a separate QThread so the proverbial bosoms are
> raised.
> If I could pass the execution of the OpenGL window functions I'm calling to
> the QThread I set up for the OpenGL window everything should run fine. I
> don't think it will be possible, to be honest, I'm just interested to know.

Since you're using Qt 4, I suggest you do this with signals and slots. If you 
connect a signal from an object owned by one thread to a slot in an object 
from another thread, Qt will do the event stuff for you. Your code will run 
in the thread that owns the slot object.



Thorsen Consulting ApS - Qt consulting services

To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with 
"unsubscribe" in the subject or the body.
List archive and information: http://lists.trolltech.com/qt-interest/

<Prev in Thread] Current Thread [Next in Thread>