Transformer.cpp:10: error: undefined reference to `vtable for Transformer'
-
Hi, people!
I'm quite a novice in Qt programing, but I have fine background in c++.
Currently, I'm trying to create one small program, with 3 classes. Two of them inherit directly QObject, but with one of them (Transformer), I have a problem with constructor:@Transformer::Transformer (QObject * parent) : QObject (parent)
{
...
}@When I try to compile all project, linker returns the error from the title.
The funny thing is, when I copy only this class (ie. transformer.h and transformer.cpp) and main.cpp to some tmp folder, compilation is done without any error.
Any ideas?
-
What does your *.pro file look like? Did you use the Q_OBJECT macro in the declaration of the QObject derived classes? Did moc run? Were the sources generated by moc compiled and linked into the executable?
Edit:
By the way: this is a FAQ. Did you search for others asking the same question before posting? -
I've been looking for others with same problems. One proposed solution was to have virtual destructor. I've tried this, but without any result.
This is .pro for problematic project:
@######################################################################Automatically generated by qmake (2.01a) Tue Dec 21 10:32:26 2010
######################################################################
TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += .Input
HEADERS += mainprogram.h transformer.h wizard.h
FORMS += wizard.ui
SOURCES += main.cpp mainprogram.cpp transformer.cpp wizard.cpp@The test project (the one that compiled) have this .pro file:
@######################################################################Automatically generated by qmake (2.01a) Sun Jan 16 21:12:45 2011
######################################################################
TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += .Input
HEADERS += transformer.h
SOURCES += main.cpp transformer.cpp@There is Q_OBJECT macro at the beginning of Transformer class.
I Tried with „make clean“ and make again, with no results.
I don't understand what have happened, but, when I deleted every auto-generated file, including deleting .pro file and Makefile, „qmake -project“ created same .pro file; but then compilation went OK. I guess there was some problem in Makefile, but I didn't save previous one.I'm sorry if I've raised topic for nothing, but I'm still confused with this problem (even though the problem had gone now).
-
[quote author="Volker" date="1295213704"]Sometimes you have to re-run qmake to catch up changes.[/quote]
This is probably the correct solution. I've done this several times myself. The standard make commands ( make, make clean, etc ) don't remake the MOC objects. Running qmake rebuilds the MOC objects for your code (since it inherits QObject), and then when you run a make, it is able to properly link to the MOC objects.