Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. 3rd Party Software
  4. Slot in inherited class is not working...

Slot in inherited class is not working...

Scheduled Pinned Locked Moved 3rd Party Software
6 Posts 4 Posters 7.3k 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.
  • P Offline
    P Offline
    phamtv
    wrote on last edited by
    #1

    I have an inherited class from a base class that is derived from QObject. Can someone tell me why my inherited class slot is not being invoked..

    @
    class cls_A : public QObject
    {
    Q_OBJECT

    private:
    explicit cls_A(QObject *parent = 0);

    // etc......
    

    }

    class cls_B : public cls_A
    {
    private:
    cls_B()
    {
    // instantiate Serial Device Enumerator and get available serial ports
    m_sde = new SerialDeviceEnumerator(this);
    connect(m_sde, SIGNAL(hasChanged(QStringList)), this, SLOT(GetDevices(QStringList)));
    m_sde->setEnabled(true);
    }

    private slots:
    void GetDevices(const QStringList &list)
    {
    // do something....
    }
    //......
    }
    @

    I run the application but GetDevices is not being invoked... Does cls_B have to have the Q_OBJECT declaration?

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

      Yes, every class that inherits from QObject - regardless wheter direct or in an inheritance path - must include the Q_OBJECT macro in the private section of the class definition.

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • P Offline
        P Offline
        phamtv
        wrote on last edited by
        #3

        when I do place the Q_OBJECT macro, I get an error indicating ¨error: undefined reference to `vtable for cls_B¨... what does this error imply?

        1 Reply Last reply
        0
        • G Offline
          G Offline
          goetz
          wrote on last edited by
          #4

          Did you re-run qmake? It must pick up the new header and include some additional build steps for a QObject class with the Q_OBJECT macro in it. You also must add the header file to the HEADERS variable in the .pro file.

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0
          • A Offline
            A Offline
            anselmolsm
            wrote on last edited by
            #5

            Also, if you declare and implement classes in the same file filename, you'll need a

            @
            #include "filename.moc"
            @

            Anselmo L. S. Melo (anselmolsm)

            1 Reply Last reply
            0
            • P Offline
              P Offline
              Polto
              wrote on last edited by
              #6

              hi i think i works for me but
              try to put the implement of the class constructor and other function in a cpp file not within the class
              and put Q_OBJECT for the two classes

              Polto

              1 Reply Last reply
              0

              • Login

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