PDA

View Full Version : BlockingQueuedConnection hang



^NyAw^
15th February 2010, 19:50
Hi,

My application have 2 threads, one to grab images from a camera and the second to perform some process to the images.

I'm trying to use "BlockingQueuedConnection" to emit image pointers(from the process thread)that are displayed into the Main Thread.

It works perfectly until I stop the threads, where the application hangs.

squidge
15th February 2010, 23:28
Why a BlockingQueuedConnection?

Where are you stopping the threads?

^NyAw^
15th February 2010, 23:45
Hi,

I'm trying to use BloquingConnection to simulate that the thread perform all display process. It works with QueuedConnection but I want the other behaviour

I'm stopping the threads into the parents class.

Note that it works with QueuedConnection.

Tanuki-no Torigava
16th February 2010, 04:20
Did you try to read the notification about threads and concurrency for the signals and slots? Look here and check special note about signaling in different modes. Shortly, only queued mode is eligible for inter-thread communications.

Regards,

^NyAw^
16th February 2010, 10:16
Hi,

As I read in the BlockingQueuedConnection, it's the same as QueuedConnection but the emmiter thread stops until the other thread(main thread in this case) finish the execution of the slot.

The threads are running in "run" method, and don't have it's own event loop. Maybe it's not possible because it don't have an event loop?

Thanks,

Tanuki-no Torigava
16th February 2010, 21:04
Not really.


Each thread can have its own event loop. The initial thread starts its event loops using QCoreApplication::exec(); other threads can start an event loop using QThread::exec(). Like QCoreApplication, QThread provides an exit(int) function and a quit() slot.

An event loop in a thread makes it possible for the thread to use certain non-GUI Qt classes that require the presence of an event loop (such as QTimer, QTcpSocket, and QProcess). It also makes it possible to connect signals from any threads to slots of a specific thread. This is explained in more detail in the Signals and Slots Across Threads section below.

The trick comes that you should process those events manually or rely upon
exec() method from
QThread. Just check if you call it at the end of the run. Also if you want something in separate thread - then declare, create, bind, use and destroy that inside
run().

Also, a piece of code will help to detect the mistake.

Good luck,

^NyAw^
17th February 2010, 10:00
Hi,

I know that using exec will make the thread to have it's own event loop, but I'm using the thread on the other behaviour. Practically it's a infinite loop(until a boolean value goes false) and the thread waits when there is no data to process. So in this case I can't use an event loop into the thread.

Lesiok
17th February 2010, 19:30
Hi,

I know that using exec will make the thread to have it's own event loop, but I'm using the thread on the other behaviour. Practically it's a infinite loop(until a boolean value goes false) and the thread waits when there is no data to process. So in this case I can't use an event loop into the thread.

Yes You can. In example something like this :
class MySuperWorker : public QThread
{
.
.
.
protected:
void run();
slots :
void makePartOfJob();
}

void MySuperWork::run()
{
.
.
.
//activate one part of job
QTimer::singleShot(0,this,SLOT(makePartOfJob()));
exec();
}

void MySuperWork::makePartOfJob()
{
//
//here do a part of job
//one course of old while loop
//
if( !end_of_job )
//activate next part of job
QTimer::singleShot(0,this,SLOT(makePartOfJob()));
}