(sorry for my english)
I have the same problem .. signal is not emitted ...i know that i need to add a event loop to the app but i don't know where and how ..
My app is a producer/consumer problem that i solve with WaitConditions and a Circular Buffer.. So i have a main Thread and two sub-threads Producer and Consumer
i the code the Producer emit a signal that i need to use to update some information to show.
This is a console app.
Some snippet of the code:
ProducerThread
ProcessingThread
::ProcessingThread(FrameBuffer
*imageBuffer,
double inputSourceWidth,
double inputSourceHeight,
QObject *parent
) :QThread(parent
){ this->buffer = imageBuffer;
this->stopped = false;
}
void ProcessingThread::run(){
while(1){
// Stop thread if stopped=TRUE //
stoppedMutex.lock();
if (stopped)
{
stopped=false;
stoppedMutex.unlock();
break;
}
stoppedMutex.unlock();
// Get frame from queue
this->currentFrame = buffer->getFrame();
if(this->currentFrame.empty()==false){
//Do the heavy work
emit newFrame();
}else{
qDebug()<<"Se recibio un frame NULL";
}
}
qDebug()<<"Deteniendo el procesado";
}
ProcessingThread::ProcessingThread(FrameBuffer *imageBuffer, double inputSourceWidth, double inputSourceHeight,QObject *parent) :QThread(parent){
this->buffer = imageBuffer;
this->stopped = false;
}
void ProcessingThread::run(){
while(1){
// Stop thread if stopped=TRUE //
stoppedMutex.lock();
if (stopped)
{
stopped=false;
stoppedMutex.unlock();
break;
}
stoppedMutex.unlock();
// Get frame from queue
this->currentFrame = buffer->getFrame();
if(this->currentFrame.empty()==false){
//Do the heavy work
emit newFrame();
}else{
qDebug()<<"Se recibio un frame NULL";
}
}
qDebug()<<"Deteniendo el procesado";
}
To copy to clipboard, switch view to plain text mode
The ConsumerThread
ConsumerThread
::ConsumerThread(FrameBuffer
*buffer,
int deviceNumber
):QThread(), imageBuffer
(buffer
){ // Open camera
capture = VideoCapture(deviceNumber);
// Initialize variables
stopped=false;
}
void ConsumerThread::run()
{
while(1)
{
/////////////////////////////////
// Stop thread if stopped=TRUE //
/////////////////////////////////
stoppedMutex.lock();
if (stopped)
{
stopped=false;
stoppedMutex.unlock();
break;
}
stoppedMutex.unlock();
/////////////////////////////////
/////////////////////////////////
// Capture and add frame to buffer
//....
//....
}
qDebug() << "Stopping capture thread...";
} // run()
ConsumerThread::ConsumerThread(FrameBuffer *buffer, int deviceNumber):QThread(), imageBuffer(buffer){
// Open camera
capture = VideoCapture(deviceNumber);
// Initialize variables
stopped=false;
}
void ConsumerThread::run()
{
while(1)
{
/////////////////////////////////
// Stop thread if stopped=TRUE //
/////////////////////////////////
stoppedMutex.lock();
if (stopped)
{
stopped=false;
stoppedMutex.unlock();
break;
}
stoppedMutex.unlock();
/////////////////////////////////
/////////////////////////////////
// Capture and add frame to buffer
//....
//....
}
qDebug() << "Stopping capture thread...";
} // run()
To copy to clipboard, switch view to plain text mode
So i have a Controller class to get access to this threads
and i Show class to execute this using the controller
The Show class:
qDebug()<<"Iniciando..";
controlador = new Controlador(3,3,0);
}
void Show::start(){
qDebug()<"Start";
if(controlador->isCameraConnected()){
connect(controlador->processing,SIGNAL(newFrame()),this,SLOT(updateFrame()),Qt::QueuedConnection);
controlador->capture->start();
controlador->processing->start();
controlador->capture->wait();
controlador->processing->wait();
controlador->disconnectCamera();
}
}
void Show::updateFrame(){
qDebug()<<"Update Frame";
}
Show::Show(QObject *parent) :QObject(parent){
qDebug()<<"Iniciando..";
controlador = new Controlador(3,3,0);
}
void Show::start(){
qDebug()<"Start";
if(controlador->isCameraConnected()){
connect(controlador->processing,SIGNAL(newFrame()),this,SLOT(updateFrame()),Qt::QueuedConnection);
controlador->capture->start();
controlador->processing->start();
controlador->capture->wait();
controlador->processing->wait();
controlador->disconnectCamera();
}
}
void Show::updateFrame(){
qDebug()<<"Update Frame";
}
To copy to clipboard, switch view to plain text mode
But the signal newFrame or is never emitted or the slot updataFrame don't receive the signal..
any idea???
Bookmarks