PDA

View Full Version : QThreads - queued connections



freekill
12th January 2010, 01:04
I'm trying to pass on a QImage from a worker thread (renderingThread) to my main thread for painting. Most of the code I used are recycled from the Mandelbrot Example (http://qt.nokia.com/doc/4.6/threads-mandelbrot.html). However, I'm getting an error from the emitted signal from my rendering thread.

In member function 'virtual void RenderingThread::run()' : error: no matching function for call to 'RenderingThread::renderedImage(QImage*)' candidates are: void RenderingThread::renderedImage(QImage&)

I'm passing along a reference to a QImage and not a pointer. Even the call to my function takes a reference and not a pointer. Here's some codes.

//webcam.cpp
renderingThread = new RenderingThread(imagebuffer,waitcondition) //thread is given pointers to a buffer and a wait condition

qRegisterMetaType<QImage>("QImage");
connect(&renderingThread, SIGNAL(renderedImage(QImage& )), this, SLOT(updatePixmap(QImage& )));
connect(startButton, SIGNAL(clicked()), this, SLOT(startThreads()));

//renderingthread.h
signals:
void renderedImage(QImage& displayImage);
private:
QImage displayImage;

//renderingthread.cpp
void RenderingThread::run(){
while (!halt){
//rendering process()...
emit renderedImage(&displayImage);
}
}
What could be wrong?

wysota
12th January 2010, 03:34
You are passing a pointer:

emit renderedImage(&displayImage);
To pass a reference simply do:

emit renderedImage(displayImage);
The compiler will know it should pass a reference and not a copy by looking at the signature of the method.

freekill
12th January 2010, 04:42
Thanks. I guess I'm getting closer to my results however,

emit renderedImage(displayImage);
is now giving me this error:
undefined reference to 'RenderingThread::renderedImage(QImage&)'

wysota
12th January 2010, 08:43
You either didn't declare the signal or you forgot the Q_OBJECT macro in your class header.

faldzip
12th January 2010, 08:52
//webcam.cpp
renderingThread = new RenderingThread(imagebuffer,waitcondition) //thread is given pointers to a buffer and a wait condition

qRegisterMetaType<QImage>("QImage");
connect(&renderingThread, SIGNAL(renderedImage(QImage& )), this, SLOT(updatePixmap(QImage& )));

What could be wrong?
renderingThread is already a pointer so &renderingThread is a pointer to pointer (type RenderingThread**) - I guess it is not what you want. Just pass renderingThread to connect() method.