PDA

View Full Version : Qthread Issue?



vishal.chauhan
29th March 2007, 06:33
Hi All,

I m working on Qt 4.2.2 on my Intel Mac.

I m new to QThread.

I have a simple QThread program in which I have a call

class MyThread : public QThread
{
public:
void run();
};

and I m reimplementing the run as ..

void MyThread::run()
{

Form1 *myForm;
myForm->CallThread();
}

which is calling the CallThread function of the form1 class in which I m starting my Thread.

MyThread fileThread;

fileThread.start();
fileThread.wait();

If I donot use the wait the Thread will not start.
But now then thread is started and call the function

void Form1::CallThread()
{

QMessageBox::information(0,"Stellar Phoenix","I m in Thread calling Function");


}

and show the Message .
But my Question are

The Program is Get hanged after showing the Message and also give error in log that We can not use font and text outside the Gui Thread.

I have used flag to terminate the thread but its not working for me.

If anybody knows then plz help me.

Thanks.

danadam
29th March 2007, 08:15
Hi All,
Hi, first of all use
tags

[code]
class MyThread : public QThread
{
public:
void run();
}

void MyThread::run()
{
Form1 *myForm;
myForm->CallThread();
}

void Form1::CallThread()
{
QMessageBox::information(0,"Stellar Phoenix","I m in Thread calling Function");
}

The Program is Get hanged after showing the Message and also give error in log that We can not use font and text outside the Gui Thread.

You are not allowed to use Gui classes (like QMessageBox) in your own threads. But you can for example emit a signal from your thread which is connected with a slot working in Gui (main) thread which will display a message box.

vishal.chauhan
29th March 2007, 08:47
Thanks for Reply.

But I donot know How can Pass Signal to the Main Thread and Recieve that signal in Main Thread?

jpn
29th March 2007, 08:50
Read Thread Support in Qt - Signals and Slots Across Threads (http://doc.trolltech.com/4.2/threads.html#signals-and-slots-across-threads) and take a look at the examples mentioned.