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. Signal is not emitted

Signal is not emitted

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 4 Posters 1.4k Views
  • 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 have the following code:
    imagecorrecctbutton.h:

     signals:
      void selectedFileChanged(QString& fileName);
    

    imagecorrectbutton.cpp:

    void ImageCorrectButton::setSelectedFile(const QString& val) {
      if(m_selectedFile == val) {
        return;
      }
      m_selectedFile = val;
      QSignalSpy spy(ImageCorrectButton::m_mainButton, SIGNAL(selectedFileChanged (QString)));
    
      if(!m_selectedFile.isEmpty()) {
        m_mainButton->setText(QString());
        m_mainButton->setIcon(QIcon(m_selectedFile));
        m_mainButton->setIconSize(QSize(100, 100));
        emit selectedFileChanged(m_selectedFile);
    
        //checking signal
        QCOMPARE(spy.count(), 1);
        QList<QVariant> arguments = spy.takeFirst();
        QVERIFY(arguments.at(0).toBool() == 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.

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      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
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      G 1 Reply Last reply
      4
      • dheerendraD dheerendra

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

        G Offline
        G Offline
        gabor53
        wrote on last edited by
        #3

        @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?

        jsulmJ 1 Reply Last reply
        0
        • beeckscheB Offline
          beeckscheB Offline
          beecksche
          wrote on last edited by
          #4

          @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);
          

          or

          void selectedFileChanged(const QString& fileName);
          
          1 Reply Last reply
          0
          • dheerendraD Offline
            dheerendraD Offline
            dheerendra
            Qt Champions 2022
            wrote on last edited by
            #5

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

            Dheerendra
            @Community Service
            Certified Qt Specialist
            http://www.pthinks.com

            1 Reply Last reply
            0
            • G gabor53

              @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?

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

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

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              1

              • Login

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