[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
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>
- {
- Q_OBJECT
- public:
- ATimer();
- };
- #endif // ATIMER_H
- #include "atimer.h"
- ATimer::ATimer()
- {
- }
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.
6 replies
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.
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
You must log in to post a reply. Not a member yet? Register here!


