Thursday, August 21st 2008, 5:06am UTC+1

You are not logged in.

  • Login
  • Register

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains how this page works. You must be registered before you can use all the page's features. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Friday, January 23rd 2004, 10:37pm

Fixing "undefined reference to `vtable ..."

Hi All,

Sometimes the linking stage of compiling might fail with the rather confusing error:

undefined reference to `vtable for MyWidget`

The short answer is:
Don't put class definitions in .cpp files when they have the Q_OBJECT macro.


ie if there are signals or slots in a class, ensure the definition is in a header file. Otherwise, moc doesn't see it and do all its magic, and so a lot of required code isn't generated.



Q: What is a vtable? A: Virtual Table

The vtable is an internal structure used for virtual overriding etc, which is heavily used in QT.
ie:
class MyWidget : public QWidget
{
Q_OBJECT

public slots:
virtual void show(); // vtable will be used for this.
};


Hope that helps someone :)

Debboy
  • Go to the top of the page

rms

Beginner

2

Sunday, January 25th 2004, 1:25pm

RE: Fixing "undefined reference to `vtable ..."

There is a way to put subclasses of QObject in a .cpp file. If your .cpp file is foo.cpp, then just put a

#include "foo.moc"

somewhere in the foo.cpp file (and run qmake again).

Rainer
  • Go to the top of the page

Rate this thread