Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Qt 6
  4. Undefined reference to staticMetaObject
Forum Updated to NodeBB v4.3 + New Features

Undefined reference to staticMetaObject

Scheduled Pinned Locked Moved Unsolved Qt 6
6 Posts 5 Posters 10.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
    Christina123
    wrote on last edited by
    #1

    Hello, I receive errors about Undefined reference to staticMetaObject when I have a class that is derived from a parent class which inherits QObject. I am wondering why is it?

    JKSHJ 1 Reply Last reply
    0
    • C Christina123

      Hello, I receive errors about Undefined reference to staticMetaObject when I have a class that is derived from a parent class which inherits QObject. I am wondering why is it?

      JKSHJ Online
      JKSHJ Online
      JKSH
      Moderators
      wrote on last edited by
      #2

      @Christina123 said in Undefined reference to staticMetaObject:

      I receive errors about Undefined reference to staticMetaObject

      "Undefined reference" means that you have something that is declared but not defined. See https://www.cprogramming.com/declare_vs_define.html

      I am wondering why is it?

      staticMetaObject is declared by the Q_OBJECT macro. It is then defined in the moc_*.cpp file that is auto-generated by moc.

      So, your error means that your class has the Q_OBJECT macro but it was not processed by moc. Check 2 things:

      1. By default, moc expects you to define QObject subclasses in *.h files rather than *.cpp files. If your class in in a *.cpp file, move it to a *.h file.
      2. If you have done this but still get the error, you can force moc to run by running qmake.

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      3
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #3

        @JKSH said in Undefined reference to staticMetaObject:

        you can force moc to run by running qmake

        I think the question is, are you using CMake or qmake?

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        JKSHJ 1 Reply Last reply
        0
        • VRoninV VRonin

          @JKSH said in Undefined reference to staticMetaObject:

          you can force moc to run by running qmake

          I think the question is, are you using CMake or qmake?

          JKSHJ Online
          JKSHJ Online
          JKSH
          Moderators
          wrote on last edited by
          #4

          @VRonin said in Undefined reference to staticMetaObject:

          I think the question is, are you using CMake or qmake?

          Ah yes, that's an important point!

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          D 1 Reply Last reply
          0
          • JKSHJ JKSH

            @VRonin said in Undefined reference to staticMetaObject:

            I think the question is, are you using CMake or qmake?

            Ah yes, that's an important point!

            D Offline
            D Offline
            david azolai
            wrote on last edited by
            #5

            @JKSH I have the same problem and use CMake , what can I do?

            Christian EhrlicherC 1 Reply Last reply
            0
            • D david azolai

              @JKSH I have the same problem and use CMake , what can I do?

              Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @david-azolai said in Undefined reference to staticMetaObject:

              I have the same problem and use CMake , what can I do?

              Show your CMakeLists.txt and describe exactly what you're doing / trying to do.

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              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