PDA

View Full Version : How to determine if current thread is the UI thread



huangwf
21st September 2007, 05:10
Does anybody know how to determie if current thread is the UI thread in Qt3?

Googled for the question, no luck so far ....

Thanks in advance.

winux
21st September 2007, 08:36
Just an info; I'm not sure if this would help - as far as I know the Ui thread is the main thread, the one called from main(). If you can implement comparision of the main thread and the thread you are testing, then it's a way to check.

marcel
21st September 2007, 09:24
You could add a static method to your main GUI class and return the current thread from from there. The current thread should be stored as a static member:


QThread MainClass::mGuiThread = QThread::currentThread();
...
QThread MainClass::guiThread()
{
return mGuiThread;
}


Then you could access it in other parts of the program and compare it with QThread::currentThread.