PDA

View Full Version : QThread , GUI freeze



cs_raja
18th November 2006, 02:25
Hi

IM writing a mutithreaded GUI applcation.
Im able to start a thread and from that thread Im posting a custom event. and my main window is catching that event and displaying a MEssage box

But problem is GUI main window is not responding, it is freezing .

What could be the problem.

In my application, Im posting Custom event to QMainWindow instance, is it the problem.

Im using Mythread->run() to satrt the thread, Could this be the problem ?

munna
18th November 2006, 04:12
try calling processEvents() (http://doc.trolltech.com/4.2/qcoreapplication.html#processEvents) after posting the events

^NyAw^
18th November 2006, 11:39
Hi,


Im using Mythread->run() to satrt the thread, Could this be the problem ?


I think that your problem is here. To start a Thread you have to call "start()", not "run()" method.
This is because when you call start, a new Thread is created, it has its own memory space and its own code space. Then, the "start()" method makes the Thread to execute the "run()" method so the Thread is in the "run()" method.

If you call "run()" instead of "start()" the Thread will never be created and the object that has called "run()" will execute the code of the method so a new Thread is not created. It is like the main Thread (GUI Thread) execute a infinite loop and so it is because your program freezes.

It's like Java programming. Java has a Thread class like Qt and you have to redefine the "run()" method but have to call "start()" to let the OS to create the Thread and assign it its memory and code space.

cs_raja
19th November 2006, 01:36
My custom events are processed ???
But Im not able to do anything with mouse or keyboard in the GUI Window(Thread)

jpn
19th November 2006, 10:47
You were already given the solution. You should call QThread::start() to begin the execution of the thread. QThread::start() does the actual work of starting a new thread and later then calls QThread::run() when appropriate, in the newly created thread. How do you expect a new thread to be started if you invoke run() directly? It won't magically begin a new thread. You are calling run() just like any other method. The GUI is frozen as long as your run() method keeps executing.