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. Connect() uses wrong emitter object.
Forum Updated to NodeBB v4.3 + New Features

Connect() uses wrong emitter object.

Scheduled Pinned Locked Moved Unsolved General and Desktop
connectconnectionsignalslotclass
7 Posts 5 Posters 2.7k Views 2 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.
  • K Offline
    K Offline
    Kalado
    wrote on 21 Jul 2017, 11:53 last edited by Kalado
    #1

    Hallo,
    I am having a problem with a connection and need some help.
    So I have one class A being utilized in another class B.
    I would like to connect a SIGNAL from A to a SLOT from B, within B.

    Look at some code:

    //A.h
    class task2 : public QWidget
    {
        Q_OBJECT
    public:
        task2(QWidget *parent = 0);
        ~task2();
    protected:
        void mousePressEvent(QMouseEvent *event) override;
    signals:
        void  myWidgetClicked();
    
    //A.cpp
    void A::mousePressEvent(QMouseEvent *event){
        emit myWidgetClicked();
    }
    

    I have a different connection in A using this SIGNAL within and without problems.

    B.h
    #include <A.h>
    QT_BEGIN_NAMESPACE
    class A;
    QT_END_NAMESPACE
    class B : public QMainWindow
    {
        Q_OBJECT
    private:
        A *a;
        void myFunction();
    private slots:
        void doSomething();
    
    //B.cpp
    B::B() : a (new A){
        myFunction();
    }
    
    void B:myFunction(){
        connect(a,SIGNAL(myWidgetClicked()),this,SLOT(doSomething()));
    }
    

    B is being shown in the main.cpp.

    I don't know why this doesn't work.

    Console says :

    QObject::connect: No such signal B::myWidgetClicked()
    

    But I entered "a" as the emitter.
    Any help would be much appreciated.

    Kind regards,
    Karim

    J P 2 Replies Last reply 21 Jul 2017, 12:29
    0
    • K Kalado
      21 Jul 2017, 11:53

      Hallo,
      I am having a problem with a connection and need some help.
      So I have one class A being utilized in another class B.
      I would like to connect a SIGNAL from A to a SLOT from B, within B.

      Look at some code:

      //A.h
      class task2 : public QWidget
      {
          Q_OBJECT
      public:
          task2(QWidget *parent = 0);
          ~task2();
      protected:
          void mousePressEvent(QMouseEvent *event) override;
      signals:
          void  myWidgetClicked();
      
      //A.cpp
      void A::mousePressEvent(QMouseEvent *event){
          emit myWidgetClicked();
      }
      

      I have a different connection in A using this SIGNAL within and without problems.

      B.h
      #include <A.h>
      QT_BEGIN_NAMESPACE
      class A;
      QT_END_NAMESPACE
      class B : public QMainWindow
      {
          Q_OBJECT
      private:
          A *a;
          void myFunction();
      private slots:
          void doSomething();
      
      //B.cpp
      B::B() : a (new A){
          myFunction();
      }
      
      void B:myFunction(){
          connect(a,SIGNAL(myWidgetClicked()),this,SLOT(doSomething()));
      }
      

      B is being shown in the main.cpp.

      I don't know why this doesn't work.

      Console says :

      QObject::connect: No such signal B::myWidgetClicked()
      

      But I entered "a" as the emitter.
      Any help would be much appreciated.

      Kind regards,
      Karim

      J Offline
      J Offline
      joeQ
      wrote on 21 Jul 2017, 12:29 last edited by
      #2

      @Kalado Hi,friend,welcome .

      You write wrong name of signal.

      signals:
          void  myWidgetClicked(); ///< this is your A's signal define
      

      But,

      void B:myFunction(){
          connect(a,SIGNAL(myWidgetC L icked()),this,SLOT(doSOmething())); ///< Notes the spelling error ā€˜L’ => 'l'
      }
      

      Just do it!

      1 Reply Last reply
      0
      • K Offline
        K Offline
        Kalado
        wrote on 21 Jul 2017, 13:16 last edited by
        #3

        Hi joe,
        unfortunately this error is in this post only, the source code is without spelling errors.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          artwaw
          wrote on 21 Jul 2017, 13:37 last edited by
          #4

          Have you tried to make slot public instead of private?

          For more information please re-read.

          Kind Regards,
          Artur

          1 Reply Last reply
          0
          • T Offline
            T Offline
            taedium
            wrote on 21 Jul 2017, 19:07 last edited by
            #5

            @Kalado In principal it should work. Please paste your actual code, that at least compiles.

            1 Reply Last reply
            0
            • P Offline
              P Offline
              Pradeep Kumar
              wrote on 25 Jul 2017, 06:51 last edited by
              #6

              Hi,

              @Kalado

              try the below code, to have a signal emitted from one class to another,

              "A.h"

              class A : public QWidget
              {
                  Q_OBJECT
              
              public:
                  A(QWidget *parent = 0);
                  ~A();
              
              
                  B *m_second;
              
                  void mousePressEvent(QMouseEvent *event) override;
              
              signals:
                  void  myWidgetClicked();
              };
              

              "A.cpp"

              A::A(QWidget *parent)
                  : QWidget(parent)
              {
                  m_second = new B;
                  connect(this,SIGNAL(myWidgetClicked()),m_second,SLOT(getEventSlot()));
              }
              
              void A::mousePressEvent(QMouseEvent *event)
              {
                  qDebug () << "mouse clicked :" << endl;
                  emit myWidgetClicked();
              }
              

              "B.h"

              class B : public QWidget
              {
                  Q_OBJECT
              public:
                  explicit B(QWidget *parent = 0);
              
              signals:
              
              public slots:
                  void getEventSlot();
              };
              

              "B.cpp"

              B::B(QWidget *parent) : QWidget(parent)
              {
              }
              
              void B::getEventSlot()
              {
                  qDebug () << Q_FUNC_INFO << "event came to slot of Class B on mouse clicked :" << endl;
              }
              

              Thanks,

              Pradeep Kumar
              Qt,QML Developer

              1 Reply Last reply
              0
              • K Kalado
                21 Jul 2017, 11:53

                Hallo,
                I am having a problem with a connection and need some help.
                So I have one class A being utilized in another class B.
                I would like to connect a SIGNAL from A to a SLOT from B, within B.

                Look at some code:

                //A.h
                class task2 : public QWidget
                {
                    Q_OBJECT
                public:
                    task2(QWidget *parent = 0);
                    ~task2();
                protected:
                    void mousePressEvent(QMouseEvent *event) override;
                signals:
                    void  myWidgetClicked();
                
                //A.cpp
                void A::mousePressEvent(QMouseEvent *event){
                    emit myWidgetClicked();
                }
                

                I have a different connection in A using this SIGNAL within and without problems.

                B.h
                #include <A.h>
                QT_BEGIN_NAMESPACE
                class A;
                QT_END_NAMESPACE
                class B : public QMainWindow
                {
                    Q_OBJECT
                private:
                    A *a;
                    void myFunction();
                private slots:
                    void doSomething();
                
                //B.cpp
                B::B() : a (new A){
                    myFunction();
                }
                
                void B:myFunction(){
                    connect(a,SIGNAL(myWidgetClicked()),this,SLOT(doSomething()));
                }
                

                B is being shown in the main.cpp.

                I don't know why this doesn't work.

                Console says :

                QObject::connect: No such signal B::myWidgetClicked()
                

                But I entered "a" as the emitter.
                Any help would be much appreciated.

                Kind regards,
                Karim

                P Offline
                P Offline
                Pradeep Kumar
                wrote on 25 Jul 2017, 06:54 last edited by Pradeep Kumar
                #7

                @Kalado said in Connect() uses wrong emitter object.:

                Look at some code:

                //A.h
                class task2 : public QWidget
                {
                    Q_OBJECT
                public:
                    task2(QWidget *parent = 0);
                    ~task2();
                protected:
                    void mousePressEvent(QMouseEvent *event) override;
                signals:
                    void  myWidgetClicked();
                
                //A.cpp
                void A::mousePressEvent(QMouseEvent *event){    /// use the respective classname
                    emit myWidgetClicked();
                }
                

                If ur using Classname as task2 , use

                void task2::mousePressEvent(QMouseEvent *event){
                    emit myWidgetClicked();
                 }
                

                Thanks,

                Pradeep Kumar
                Qt,QML Developer

                1 Reply Last reply
                0

                1/7

                21 Jul 2017, 11:53

                • Login

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