Qt Forum

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

    Update: Forum Guidelines & Code of Conduct

    [SOLVED] getting repeated problem undefined reference to vtable with the QtCreator

    General and Desktop
    6
    7
    13821
    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.
    • M
      moorepe last edited by

      Every now and then i get a problem which i suspect is a problem in QtCreator because it eventually compiles properly after touching the project file. I get undefined reference to vtable for a newly created class constructor (code and pro file is below). After getting the error i simplified the code to very basic form (seen below) and still the problem remained even after repeated Clean project and rebuild steps.

      Then i turned my attention to the pro file where I suspected that the HEADERS line had some weird character in it and changed the line from ...
      @
      HEADERS +=
      atimer.h
      @
      to ....
      @
      HEADERS += atimer.h
      @
      it then worked. Then i did a ctrl Z to back out the changes but could not reproduce the error.

      Has anyone else seen this behavior?

      Seen on XP and Win 7.

      @
      #ifndef ATIMER_H
      #define ATIMER_H
      #include <QObject>
      class ATimer : public QObject
      {
      Q_OBJECT
      public:
      ATimer();
      };
      #endif // ATIMER_H

      #include "atimer.h"
      ATimer::ATimer()
      {
      }
      @

      @
      QT += core

      QT -= gui

      TARGET = TimerTest
      CONFIG += console
      CONFIG -= app_bundle

      TEMPLATE = app

      SOURCES += main.cpp
      atimer.cpp

      HEADERS +=
      atimer.h
      @

      Thanks for replies. It is indeed solved by running qmake. When I touched the project file it implicitly runs qmake.

      For anyone interested, the reason this happens is when you add the Q_OBJECT macro (the magic Qt compiler thing) to a class that was previously build without it.

      When you add Q_OBJECT to your class, the moc.exe (the meta object compiler) needs to run on your source to generate a moc_<classname>.cpp for proper compilation.

      So after rerunning QMake your project will fill in these additional targets in the makefiles.

      @
      compiler_moc_header_make_all: debug/moc_atimer.cpp
      compiler_moc_header_clean:
      -$(DEL_FILE) debug\moc_atimer.cpp
      debug/moc_atimer.cpp: ../../LearnQt/TimerTest/atimer.h
      C:\Qt\2010.04\qt\bin\moc.exe $(DEFINES) $(INCPATH) -D__GNUC__ -DWIN32 ....\LearnQt\TimerTest\atimer.h -o debug\moc_atimer.cpp
      @

      1 Reply Last reply Reply Quote 0
      • F
        fluca1978 last edited by

        Never seen on Linux, I don't develop under Windows so I cannot test and confirm. Should not this thread belongs to the tools section?

        1 Reply Last reply Reply Quote 0
        • L
          lgeyer last edited by

          Re-running qmake should solve to problem.

          1 Reply Last reply Reply Quote 0
          • M
            moorepe last edited by

            When you rebuild is that not rerunning qmake ?

            1 Reply Last reply Reply Quote 0
            • H
              Hostel last edited by

              Sometimes this error is when we add a new file which is QObject type and we doesn't run qmake. I'm not sure in 100% but I think that full build forces a qmake.

              1 Reply Last reply Reply Quote 0
              • M
                mkoskim last edited by

                Yes, I have noticed that at least Qt Creator version that comes with Ubuntu has some problems handling dependencies for generated files. Re-running qmake and rebuilding the project usually helps. You might of course get the same error message, if you have no implementation to a virtual function; check that your header and implementation matches, if the problem does not go away with rebuilding.

                http://mkoskim.wordpress.com
                http://mkoskim.drivehq.com
                http://mkoskim.deviantart.com

                1 Reply Last reply Reply Quote 0
                • A
                  Asperamanca last edited by

                  I get these errors every couple of days. My standard procedure (until it works) is:
                  -) Run qmake
                  -) Manually delete the obj files of the source modules I know need to be re-compiled, maybe also delete certain Makefiles (if I am in a multi-sub-project environment, and only want to rebuild one of those projects)
                  -) Do a clean, manually delete any Makefiles, and rebuild

                  Usually, deleting the corresponding obj file is enough.

                  Edit: BTW, Windows XP here

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post