PDA

View Full Version : problem: qthread emitting a signal with any object type



criss
15th April 2007, 12:00
hi.

i'm using qt 4.2.x on visual studio + winxp and maybe it sound silly, but the following problem irritates me a little bit:

there is a qthread class, which tires to get new images from a device. the device has a "grab timeout". if a timeout occurs, an exception is thrown. if a new image could be grabbed, a signal should be emitted, transfering the new image to the calling (main/parent) thread for processing/displaying or what ever.

i tried like this...

the threads run method:


void getimg_thread::run()
{
while(!quitthread)
{
try
{
grab_image(&img);
emit newimg(img);
msleep(1);
}
catch(AException &ex)
{
}
}
}


the defined signal:


signals:
void newimg(imageobject);


the slot to receive and process the emitted signal:


private slots:
void newimage_received(imageobject nimg);


and finally the connect part:


connect(grabimg, SIGNAL(newimg(imageobject)), this, SLOT(newimage_received(imageobject)));


but my headache starts here: the connect does not work somehow, my slot is never called. i tried many things, but without any luck.

it somehow just worked as i emitted an "int". then my slot was called properly. i also tried to emit a signal with a QList<int>, which is also working, e.g.:


...
signals:
void newimg(const QList<int>*);
...
QList<int> *a = new QList<int>;
a->append(1);
emit newimg(a);
...
private slots:
void newimage_received(QList<int> *nimg);
...
connect(grabimg, SIGNAL(newimg(QList<int> *)), this, SLOT(newimage_received(QList<int> *)));
...


but if i'm using my imageobject class (which is not a qt object), it won't work:


...
signals:
void newimg(QList<imageobject>*);
...
QList<imageobject> *a = new QList<imageobject>;
a->append(img);
emit newimg(a);
...
private slots:
void newimage_received(QList<imageobject> *nimg);
...
connect(grabimg, SIGNAL(newimg(QList<imageobject>*)), this, SLOT(newimage_received(QList<imageObject>*)));
...


i'm confused. why is QList<int> working and QList<imageobject> not? i mean, an emitted signal is able to transfer any object i define or not!? any ideas? help :|

regards,

criss

jpn
15th April 2007, 12:11
Custom types (imageobject) must be made known to the meta object system of Qt. See Q_DECLARE_METATYPE() (http://doc.trolltech.com/4.2/qmetatype.html#Q_DECLARE_METATYPE) and qRegisterMetaType() (http://doc.trolltech.com/4.2/qmetatype.html#qRegisterMetaType).

wysota
15th April 2007, 12:11
It's worth looking at the debugging console sometimes ;) Try running your application with console enabled and see what info you get. And then read this:
http://doc.trolltech.com/4.2/qmetatype.html#qRegisterMetaType

Argh... J-P beat me to it :)

criss
15th April 2007, 19:16
thanks a lot guys, i'm proud to know a place like this forum (which is the best among the others)...

greetings from istanbul :D

krzysztof