PDA

View Full Version : Undefined reference to 'vtable for XXX'



Sheng
16th October 2008, 19:22
I am using QT 4 to design GUI of my software.

I have a Controller class derived from QObject (because I want to use signals-slots mechanism). But when I build the project, the moc_Controller.cpp redefined some of member function in Controller.cpp and cause the compile problem. I decided to remove moc_Controller.cpp in Makefile. Then it causes link error called "Undefined reference to 'vtable for Controller".

Is that because there is some pure virtual function in QObject (I did not find it)?

Any help is appreciated, thanks.

caduel
16th October 2008, 19:52
If you use Q_OBJECT (i.e. declare signals, slots, properties, Q_ENUMs...) then you need the code compiled by moc. (The Q_OBJECT macro declares stuff the the moc-generated code defines.)

HTH

Sheng
16th October 2008, 20:18
If you use Q_OBJECT (i.e. declare signals, slots, properties, Q_ENUMs...) then you need the code compiled by moc. (The Q_OBJECT macro declares stuff the the moc-generated code defines.)

HTH

I removed the re-definition in moc_Controller, now it works fine. I do not understand why moc_Controller want to redefine my function.

caduel
17th October 2008, 08:51
moc_XXX does not redefine your functions, it implements your signals, among other things.

Sheng
17th October 2008, 16:59
moc_XXX does not redefine your functions, it implements your signals, among other things.

Thanks, so I guess I do not need to implement signals in my code.