Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Catching a signal from an other class

Catching a signal from an other class

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 671 Views 4 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    gabor53
    wrote on last edited by
    #1

    Hi,
    I'm emitting a signal in ImageCorrectButton.cpp:

    emit selectedFileChanged(m_selectedFile);
    

    How can I catch this signal in an other class (mydelegate.cpp)?
    Please show me an example if possible.
    Thank you.

    A 1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      Hi! See Signals & Slots.

      1 Reply Last reply
      4
      • G gabor53

        Hi,
        I'm emitting a signal in ImageCorrectButton.cpp:

        emit selectedFileChanged(m_selectedFile);
        

        How can I catch this signal in an other class (mydelegate.cpp)?
        Please show me an example if possible.
        Thank you.

        A Offline
        A Offline
        ambershark
        wrote on last edited by
        #3

        @gabor53 You definitely need to read the docs that @Wieland linked, but to give you the quick version:

        class MyDelegate : public QObject
        {
           Q_OBJECT
        
        // ...
        
        private slots:
           void fileChanged(QString);
        
        // ...
        }
        
        void MyDelegate::someFunction()
        {
           connect(myImageButton, SIGNAL(selectedFileChanged(QString)), this, SLOT(fileChanged(QString)));
        }
        
        void MyDelegate::fileChanged(QString)
        {
           // this gets called on signal
        }
        

        myImageButton is a pointer to your ImageCorrectButton. I assumed the m_selectedFile was a QString and added that as the param type.

        My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

        1 Reply Last reply
        4

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved