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
QtWS25 Last Chance

Undefined reference to staticMetaObject

Scheduled Pinned Locked Moved Unsolved Qt 6
6 Posts 5 Posters 10.2k 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.
  • C Offline
    C Offline
    Christina123
    wrote on 26 Apr 2021, 20:53 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?

    J 1 Reply Last reply 27 Apr 2021, 01:25
    0
    • C Christina123
      26 Apr 2021, 20:53

      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?

      J Offline
      J Offline
      JKSH
      Moderators
      wrote on 27 Apr 2021, 01:25 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
      • V Offline
        V Offline
        VRonin
        wrote on 27 Apr 2021, 14:29 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

        J 1 Reply Last reply 27 Apr 2021, 14:32
        0
        • V VRonin
          27 Apr 2021, 14:29

          @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?

          J Offline
          J Offline
          JKSH
          Moderators
          wrote on 27 Apr 2021, 14:32 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 20 Dec 2023, 10:06
          0
          • J JKSH
            27 Apr 2021, 14:32

            @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 20 Dec 2023, 10:06 last edited by
            #5

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

            C 1 Reply Last reply 20 Dec 2023, 10:10
            0
            • D david azolai
              20 Dec 2023, 10:06

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

              C Offline
              C Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on 20 Dec 2023, 10:10 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