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. [SOLVED] getting repeated problem undefined reference to vtable with the QtCreator

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

Scheduled Pinned Locked Moved General and Desktop
7 Posts 6 Posters 15.0k 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.
  • M Offline
    M Offline
    moorepe
    wrote on last edited by
    #1

    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
    0
    • F Offline
      F Offline
      fluca1978
      wrote on last edited by
      #2

      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
      0
      • L Offline
        L Offline
        lgeyer
        wrote on last edited by
        #3

        Re-running qmake should solve to problem.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          moorepe
          wrote on last edited by
          #4

          When you rebuild is that not rerunning qmake ?

          1 Reply Last reply
          0
          • H Offline
            H Offline
            Hostel
            wrote on last edited by
            #5

            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
            0
            • M Offline
              M Offline
              mkoskim
              wrote on last edited by
              #6

              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
              0
              • A Offline
                A Offline
                Asperamanca
                wrote on last edited by
                #7

                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
                0

                • Login

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