[SOLVED] getting repeated problem undefined reference to vtable with the QtCreator
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
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.
class ATimer : public QObject
#endif // ATIMER_H
QT += core
QT -= gui
TARGET = TimerTest
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
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.
C:\Qt\2010.04\qt\bin\moc.exe $(DEFINES) $(INCPATH) -D__GNUC__ -DWIN32 ....\LearnQt\TimerTest\atimer.h -o debug\moc_atimer.cpp
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?
Re-running qmake should solve to problem.
When you rebuild is that not rerunning qmake ?
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.
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.
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