Results 1 to 7 of 7

Thread: Connect signal to slot from different class

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2015
    Posts
    28
    Thanks
    10
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Connect signal to slot from different class

    Hi,

    I have a signal that I want to connect to a slot found in a different class. How do I do that?
    What I thought I could do:

    Class A header:
    Qt Code:
    1. #include "classB.h"
    2.  
    3. class ClassA
    4. {
    5.  
    6. Q_Object
    7.  
    8. public:
    9. ClassA();
    10. ...
    11. ...
    12.  
    13. signals:
    14. void stuffChange( const QString & );
    15.  
    16. private:
    17.  
    18. ClassB classb
    19. };
    To copy to clipboard, switch view to plain text mode 

    And in Class A constructor:
    Qt Code:
    1. connect(this, SIGNAL( stuffChange( const QString & ) ), &classb, SLOT( setStuff( const QString & ) ) );
    To copy to clipboard, switch view to plain text mode 

    Class B header:
    Qt Code:
    1. class ClassB
    2. {
    3.  
    4. Q_Object
    5.  
    6. public:
    7. ClassB();
    8. ...
    9. ...
    10.  
    11. public slots:
    12. void setStuff( const QString & );
    13.  
    14. private:
    15. QString stuff;
    16.  
    17. };
    To copy to clipboard, switch view to plain text mode 

    This gives me the error: LNK2019: unresolved external symbol "public: __ ...
    What is the right way to do this?
    Last edited by Leutzig; 10th December 2015 at 20:33.

Similar Threads

  1. Connect Signal/Slot to any instance of another class
    By squeegedog in forum Qt Programming
    Replies: 1
    Last Post: 8th February 2014, 08:43
  2. Can't connect a signal to a slot
    By cejohnsonsr in forum Newbie
    Replies: 5
    Last Post: 26th August 2010, 20:42
  3. Replies: 9
    Last Post: 30th June 2010, 19:36
  4. Replies: 12
    Last Post: 18th September 2008, 15:04
  5. Signal/slot looking in base class, not derived class
    By georgie in forum Qt Programming
    Replies: 2
    Last Post: 12th May 2006, 07:36

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
  •  
Qt is a trademark of The Qt Company.