Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. working on signal and slots on two different classes
Qt 6.11 is out! See what's new in the release blog

working on signal and slots on two different classes

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
9 Posts 4 Posters 1.8k 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.
  • S Offline
    S Offline
    Sriu1
    wrote on last edited by
    #1

    Hi ,
    I am trying to use signal and slots for popping up an qmessagebox window.
    The class which emits the signal is inherited from QObject, other who receives the signal is inherited from QWidget and uses macro Q_Object.
    I am facing linking error for my code, "undefined reference to signal" . I tried to ass Q_Object macro to the class which emits the signal, this gives undefined reference to `vtable for that class
    I am using cmake to build my code.
    Please provide inputs.

    J.HilkJ 1 Reply Last reply
    0
    • S Sriu1

      Hi ,
      I am trying to use signal and slots for popping up an qmessagebox window.
      The class which emits the signal is inherited from QObject, other who receives the signal is inherited from QWidget and uses macro Q_Object.
      I am facing linking error for my code, "undefined reference to signal" . I tried to ass Q_Object macro to the class which emits the signal, this gives undefined reference to `vtable for that class
      I am using cmake to build my code.
      Please provide inputs.

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      hi, @Sriu1

      wihtout actually seeing your code, I can only take a guess.

      But it sounds like the signal you're emitting, is not marked with the Q_SIGNAL makro or you're trying to missuse an actual function as a signal


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Sriu1
        wrote on last edited by Sriu1
        #3

        Hi , this is my code snippet
        In 1.h file
        class A: public QObject, public B{
        public signals:
        void Sys_SIGNAL();
        public:
        SYS_DisplayNonCriticalError();
        }
        1.cpp
        A::SYS_DisplayNonCriticalError()
        {
        emit Sys_SIGNAL();
        }
        2.h
        class MW : public QMainWindow {
        Q_OBJECT
        public slots:
        void GUI_NonCriticalErrorPOP();
        }
        2.cpp
        void MW::init(){
        A *SMG_objsysmgr = new A();
        connect (SMG_objsysmgr,SIGNAL(Sys_SIGNAL()),this,SLOT(GUI_NonCriticalErrorPOP())); }
        void MainWindow::GUI_NonCriticalErrorPOP(){
        }

        J.HilkJ 1 Reply Last reply
        0
        • S Sriu1

          Hi , this is my code snippet
          In 1.h file
          class A: public QObject, public B{
          public signals:
          void Sys_SIGNAL();
          public:
          SYS_DisplayNonCriticalError();
          }
          1.cpp
          A::SYS_DisplayNonCriticalError()
          {
          emit Sys_SIGNAL();
          }
          2.h
          class MW : public QMainWindow {
          Q_OBJECT
          public slots:
          void GUI_NonCriticalErrorPOP();
          }
          2.cpp
          void MW::init(){
          A *SMG_objsysmgr = new A();
          connect (SMG_objsysmgr,SIGNAL(Sys_SIGNAL()),this,SLOT(GUI_NonCriticalErrorPOP())); }
          void MainWindow::GUI_NonCriticalErrorPOP(){
          }

          J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by J.Hilk
          #4

          @Sriu1 said in working on signal and slots on two different classes:

          seems about right, just one thing, add

          Q_OBJECT

          also to the class that emits the signal.
          Also to be on the save side, rerun qmake after you made that change.
          0_1526638235094_cfca62e3-510d-465a-84ae-0adc64437ce8-image.png


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          S 1 Reply Last reply
          0
          • J.HilkJ J.Hilk

            @Sriu1 said in working on signal and slots on two different classes:

            seems about right, just one thing, add

            Q_OBJECT

            also to the class that emits the signal.
            Also to be on the save side, rerun qmake after you made that change.
            0_1526638235094_cfca62e3-510d-465a-84ae-0adc64437ce8-image.png

            S Offline
            S Offline
            Sriu1
            wrote on last edited by
            #5

            @J.Hilk
            I am using cmake to build my code, after adding Q_OBJECT, i am facing "undefined reference to `vtable for A"

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Hi,

              Then do a clean rebuild of your project. That will be faster.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              S 1 Reply Last reply
              0
              • SGaistS SGaist

                Hi,

                Then do a clean rebuild of your project. That will be faster.

                S Offline
                S Offline
                Sriu1
                wrote on last edited by Sriu1
                #7

                @SGaist
                I have been doing clean build , but no luck..
                Same errors exist..
                My code isn't generating moc file for 1.cpp file.. Hence vtable error still exists..
                Could you please suggest a solution for it..

                1 Reply Last reply
                0
                • J.HilkJ Offline
                  J.HilkJ Offline
                  J.Hilk
                  Moderators
                  wrote on last edited by
                  #8

                  mmh,
                  just to be sure:
                  did you #include <QObject> to the class?


                  Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                  Q: What's that?
                  A: It's blue light.
                  Q: What does it do?
                  A: It turns blue.

                  1 Reply Last reply
                  0
                  • mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    Hi
                    adding to @J-Hilk
                    Did you also read, understand and setup moc for Cmake ?
                    https://cmake.org/cmake/help/v3.0/prop_tgt/AUTOMOC.html

                    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