Results 1 to 4 of 4

Thread: problem: qthread emitting a signal with any object type

  1. #1
    Join Date
    Jul 2006
    Posts
    8
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Exclamation problem: qthread emitting a signal with any object type

    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:
    Qt Code:
    1. void getimg_thread::run()
    2. {
    3. while(!quitthread)
    4. {
    5. try
    6. {
    7. grab_image(&img);
    8. emit newimg(img);
    9. msleep(1);
    10. }
    11. catch(AException &ex)
    12. {
    13. }
    14. }
    15. }
    To copy to clipboard, switch view to plain text mode 

    the defined signal:
    Qt Code:
    1. signals:
    2. void newimg(imageobject);
    To copy to clipboard, switch view to plain text mode 

    the slot to receive and process the emitted signal:
    Qt Code:
    1. private slots:
    2. void newimage_received(imageobject nimg);
    To copy to clipboard, switch view to plain text mode 

    and finally the connect part:
    Qt Code:
    1. connect(grabimg, SIGNAL(newimg(imageobject)), this, SLOT(newimage_received(imageobject)));
    To copy to clipboard, switch view to plain text mode 

    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.:
    Qt Code:
    1. ...
    2. signals:
    3. void newimg(const QList<int>*);
    4. ...
    5. QList<int> *a = new QList<int>;
    6. a->append(1);
    7. emit newimg(a);
    8. ...
    9. private slots:
    10. void newimage_received(QList<int> *nimg);
    11. ...
    12. connect(grabimg, SIGNAL(newimg(QList<int> *)), this, SLOT(newimage_received(QList<int> *)));
    13. ...
    To copy to clipboard, switch view to plain text mode 

    but if i'm using my imageobject class (which is not a qt object), it won't work:
    Qt Code:
    1. ...
    2. signals:
    3. void newimg(QList<imageobject>*);
    4. ...
    5. QList<imageobject> *a = new QList<imageobject>;
    6. a->append(img);
    7. emit newimg(a);
    8. ...
    9. private slots:
    10. void newimage_received(QList<imageobject> *nimg);
    11. ...
    12. connect(grabimg, SIGNAL(newimg(QList<imageobject>*)), this, SLOT(newimage_received(QList<imageObject>*)));
    13. ...
    To copy to clipboard, switch view to plain text mode 

    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

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: problem: qthread emitting a signal with any object type

    Custom types (imageobject) must be made known to the meta object system of Qt. See Q_DECLARE_METATYPE() and qRegisterMetaType().
    J-P Nurmi

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: problem: qthread emitting a signal with any object type

    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/qmetaty...gisterMetaType

    Argh... J-P beat me to it

  4. #4
    Join Date
    Jul 2006
    Posts
    8
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Thumbs up Re: problem: qthread emitting a signal with any object type

    thanks a lot guys, i'm proud to know a place like this forum (which is the best among the others)...

    greetings from istanbul

    krzysztof

Similar Threads

  1. Can't create an object : initialisation problem ?
    By Nyphel in forum Qt Programming
    Replies: 5
    Last Post: 12th March 2007, 09:07
  2. cost of emitting signal
    By quickNitin in forum Newbie
    Replies: 1
    Last Post: 29th November 2006, 08:53
  3. Replies: 2
    Last Post: 17th May 2006, 21:01
  4. Replies: 4
    Last Post: 10th May 2006, 22:37

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.