Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved working on signal and slots on two different classes

    Mobile and Embedded
    4
    9
    591
    Loading More Posts
    • 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
      Sriu1 last edited by

      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.Hilk 1 Reply Last reply Reply Quote 0
      • J.Hilk
        J.Hilk Moderators @Sriu1 last edited by

        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

        Qt Needs YOUR vote: https://bugreports.qt.io/browse/QTQAINFRA-4121


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

        1 Reply Last reply Reply Quote 0
        • S
          Sriu1 last edited by 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.Hilk 1 Reply Last reply Reply Quote 0
          • J.Hilk
            J.Hilk Moderators @Sriu1 last edited by 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

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

            Qt Needs YOUR vote: https://bugreports.qt.io/browse/QTQAINFRA-4121


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

            S 1 Reply Last reply Reply Quote 0
            • S
              Sriu1 @J.Hilk last edited by

              @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 Reply Quote 0
              • SGaist
                SGaist Lifetime Qt Champion last edited by

                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 Reply Quote 0
                • S
                  Sriu1 @SGaist last edited by Sriu1

                  @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 Reply Quote 0
                  • J.Hilk
                    J.Hilk Moderators last edited by

                    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

                    Qt Needs YOUR vote: https://bugreports.qt.io/browse/QTQAINFRA-4121


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

                    1 Reply Last reply Reply Quote 0
                    • mrjj
                      mrjj Lifetime Qt Champion last edited by

                      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 Reply Quote 1
                      • First post
                        Last post