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. Build error when subclassing of subclassing from QObject
Forum Updated to NodeBB v4.3 + New Features

Build error when subclassing of subclassing from QObject

Scheduled Pinned Locked Moved General and Desktop
7 Posts 4 Posters 1.4k Views 1 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.
  • C Offline
    C Offline
    crazygun22
    wrote on last edited by
    #1

    build error is happen when subclassing of subclassing from QObject.

    is there any solution to avoid this problem?

    this is source code & error

    !http://crazygun22.g3.cc/ee.png(source code & error)!

    1 Reply Last reply
    0
    • C Offline
      C Offline
      crazygun22
      wrote on last edited by
      #2

      this is my qt version

      Qt Creator 3.3.0 (opensource)
      Based on Qt 5.4.0 (MSVC 2010, 32 bit)

      Built on Dec 8 2014 at 15:24:21

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

        Do you need Q_OBJECT in 'sub' class ? This is the source of your error.

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

        1 Reply Last reply
        2
        • C Offline
          C Offline
          crazygun22
          wrote on last edited by
          #4

          i need to send signal in both base and sub classes,
          so i wrote the Q_OBJECT in both class.

          if writing Q_OBJECT in both class is impossible, how can i send signal in both classes?

          build error is also happen when writing emit function to send signal without Q_OBJECT in Sub class

          -------------------------------Sub.h------------------------------------
          class Sub : public Base
          {
          .......
          signals:
          void sendSigKey(const QString &key) const;
          };

          -------------------------------Sub.c---------------
          void Sub::send()
          {
          emit sendSigKey("asdf");
          }
          --------------------------------Error------------
          error: undefined reference to `Sub::sendSigKey(QString const&) const'

          1 Reply Last reply
          0
          • E Offline
            E Offline
            euchkatzl
            wrote on last edited by
            #5

            Did you do a clean qmake ?

            Delete your build folder
            Run qmake
            Build your project.

            After that i think you have to remove the const qualifier in your constructor !

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

              Hi,

              To add to my fellow, when adding/removing the Q_OBJECT macro you need to run qmake once to update the build part. Then it should build cleanly

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

              1 Reply Last reply
              0
              • C Offline
                C Offline
                crazygun22
                wrote on last edited by
                #7

                thank you, SGaist

                your reply sloved my problem.

                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