Please nominate your Qt Champions for 2021!

Catching a signal from an other class

  • 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.

  • Hi! See Signals & Slots.

  • Moderators

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

    class MyDelegate : public QObject
    // ...
    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.

Log in to reply