I checked it with currentThreadId()
First I printed with qDebug(...) in my producer, after that emitted a signal, so my consumer slot would be called and done the same there.
In both cases the returned integer number is identic, soo that means same context,..damn!
What I do:
My producer-thread gets a signal from a sibling object, after that I read in my producer the data I need and do some checking. If necessery I create in that slot of my producer new consumer-threads.
After creating them I send them a signal to exec their slots.
slot of my producer:
void producer::dataisInside()
{
//1- reading data from a global thread safe storage
//2- checking the inside of the data, if a new woker is requiered
if(newWorkerIsRequired){
worker = new Worker();
//push the new worker instance in a list/pool
worker->start();
}
Qt
::HANDLE a
= QThread::currentThreadId();
qDebug("I am producer and my handle is %d",a);
}
void producer::dataisInside()
{
//1- reading data from a global thread safe storage
//2- checking the inside of the data, if a new woker is requiered
if(newWorkerIsRequired){
worker = new Worker();
//push the new worker instance in a list/pool
worker->start();
}
Qt::HANDLE a = QThread::currentThreadId();
qDebug("I am producer and my handle is %d",a);
}
To copy to clipboard, switch view to plain text mode
My worker is a simply derived from QThread and provides one slot to handle the signal which is sent by the producer.
{
....
protected:
void run();
public slots:
void testslot();
}
class Worker:: public QThread
{
....
protected:
void run();
public slots:
void testslot();
}
To copy to clipboard, switch view to plain text mode
void Worker::testslot()
{
Qt
::HANDLE b
= QThread::currentThreadId();
qDebug("I am consumer and my handle is %d",b);
}
void Worker::testslot()
{
Qt::HANDLE b = QThread::currentThreadId();
qDebug("I am consumer and my handle is %d",b);
}
To copy to clipboard, switch view to plain text mode
Maybe I should create my Workers somewhere else?
Is that the problem?
Bookmarks