Results 1 to 7 of 7

Thread: threads, signals and slots

  1. #1
    Join Date
    Mar 2009
    Posts
    6
    Thanks
    3
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Unhappy threads, signals and slots

    hi,

    im trying to use a thread to do some background work. It takes a bunch of messages and checks the status of each until it has a "finished" status.

    messagestatusthread.h

    Qt Code:
    1. class MessageStatusThread : public QThread
    2. {
    3. public:
    4. MessageStatusThread(QList<Message*> *messages);
    5. void run();
    6.  
    7. private:
    8. QList<Message*> *m_messages;
    9. QMultiMap<QString, Address*> *unfinishedMesasgeStatusMap;
    10.  
    11. QString* buildXml();
    12. void parseXml(QString data);
    13.  
    14. public slots:
    15. void messageStatusFinished(QString);
    16. };
    To copy to clipboard, switch view to plain text mode 

    messagestatusthread.cpp run method
    Qt Code:
    1. void MessageStatusThread::run()
    2. {
    3. while(!unfinishedMesasgeStatusMap->isEmpty()) {
    4.  
    5. CommunicationFacade *communication = new CommunicationFacade();
    6. connect(communication, SIGNAL(communicationFinished(QString)), this, SLOT(messageStatusFinished(QString)));
    7.  
    8. communication->sendRequest(buildXml());
    9.  
    10. sleep(30);
    11. }
    12.  
    13. }
    To copy to clipboard, switch view to plain text mode 

    I'm using the CommunicationFacade in other parts of the program but not in a separate thread and there it works.

    I get Object::connect: No such slot QThread::messageStatusFinished(QString) in messagestatusthread.cpp:34 when I run the program.

    The messageStatusFinished(QString) slot is implemented in messagestatusthread.cpp.

    Can somebody point out what I'm doing wrong?

    Thanks

  2. #2
    Join Date
    Feb 2008
    Posts
    98
    Thanks
    2
    Thanked 24 Times in 24 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: threads, signals and slots

    You forgot to add the Q_OBJECT macro in the class definition.

  3. The following user says thank you to victor.fernandez for this useful post:

    cyclic (2nd September 2009)

  4. #3
    Join Date
    Mar 2009
    Posts
    6
    Thanks
    3
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: threads, signals and slots

    when I add that I get:

    /src/messagestatusthread.cpp:13: undefined reference to `vtable for MessageStatusThread'

  5. #4
    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: threads, signals and slots

    Rerun qmake afterwards.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. The following user says thank you to wysota for this useful post:

    cyclic (2nd September 2009)

  7. #5
    Join Date
    Mar 2009
    Posts
    6
    Thanks
    3
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: threads, signals and slots

    thanks, that helped

    but now things get really strange.
    Now i don't get any errors but the slot is not executed, nothing happens

  8. #6
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: threads, signals and slots

    you should add exec (for enabling event loop in a thread) in you run method if you need process signal in you thread.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  9. The following user says thank you to spirit for this useful post:

    cyclic (2nd September 2009)

  10. #7
    Join Date
    Mar 2009
    Posts
    6
    Thanks
    3
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: threads, signals and slots

    thank you all!

    now it works

Similar Threads

  1. Signals and Slots Problem
    By GenericProdigy in forum Qt Programming
    Replies: 4
    Last Post: 2nd February 2009, 09:06
  2. Signals and Slots
    By 83.manish in forum Qt Programming
    Replies: 3
    Last Post: 30th June 2008, 10:31
  3. Signals and Slots Across Threads
    By themusicalguy in forum Qt Programming
    Replies: 1
    Last Post: 26th October 2007, 11:16
  4. Connecting signals & slots across different threads
    By jyoti kumar in forum Qt Programming
    Replies: 4
    Last Post: 16th May 2006, 12:40
  5. [QT4] threads, signals, and slots, please help.
    By ucntcme in forum Qt Programming
    Replies: 12
    Last Post: 25th January 2006, 14:23

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.