Signal is not emitted

  • Hi,
    I have the following code:

      void selectedFileChanged(QString& fileName);


    void ImageCorrectButton::setSelectedFile(const QString& val) {
      if(m_selectedFile == val) {
      m_selectedFile = val;
      QSignalSpy spy(ImageCorrectButton::m_mainButton, SIGNAL(selectedFileChanged (QString)));
      if(!m_selectedFile.isEmpty()) {
        m_mainButton->setIconSize(QSize(100, 100));
        emit selectedFileChanged(m_selectedFile);
        //checking signal
        QCOMPARE(spy.count(), 1);
        QList<QVariant> arguments = spy.takeFirst();
        QVERIFY( == true);

    Every time I get the following message:
    QSignalSpy: No such signal: 'selectedFileChanged(QString)'
    QObject::connect: No such signal ImageCorrectButton::selectedFileChanged(QString) in ..\Folkfriends_1_0\mydelegate.cpp:137
    What am I doing wrong when I'm trying to emit the signal?
    Thank you for your help.

  • selectedFileChanged Signal is presented in imagecorrectbutton class. U r giving argument as main button. Hence the issue. Please correct the same. It should work.

  • @dheerendra
    I changed the connect:

          connect(ImageCorrectButton, SIGNAL(selectedFileChanged(QString)), this, SLOT(fileChanged()));

    Now it says
    "QObject::connect: No such signal ImageCorrectButton::selectedFileChanged(QString) in ..\Folkfriends_1_0\mydelegate.cpp:137

    The signal is in imagecorrectbutton:

    emit selectedFileChanged(m_selectedFile);

    What I am still missing?

  • @gabor53
    In your signal you use a reference QString&

    void selectedFileChanged(QString& fileName);

    Maybe you have to add this in the connection.

    But, i think references in signals are not a good choice, i normally use copies or const references, like

    void selectedFileChanged(QString fileName);


    void selectedFileChanged(const QString& fileName);

  • as pointed out already by the previous post, it is is the issue of signature mismatch. Please correct signal signatures. it should work.

  • Moderators

    @gabor53 You have to provide a pointer to ImageCorrectButton instance instead of class itself when using connect():

    // This is done somewhere in your code:
    ImageCorrectButton *imageCorrectButton;
    imageCorrectButton = new ImageCorrectButton();
    connect(imageCorrectButton, SIGNAL(selectedFileChanged(QString)), this, SLOT(fileChanged()));

    connect connects two instances: you cannot connect a class to something.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.