“undefined reference to vtable” seems to be a common problem with Qt’s meta-object system in combination with GCC.
The main cause due to GCC is described here: http://gcc.gnu.org/faq.html#vtables
But with QObject it gets a bit more complex. When you use the macro Q_OBJECT, you define some virtual methods which might trigger the above GCC error under certain circumstances. So make sure your use of the Q_OBJECT macro fulfills the following requirements:
- Make sure the Q_OBJECT macro is present in the definition of all QObject-derived classes
- Make sure you define your QObject-derived classes in your header files ONLY
- Make sure all of your header files are listed in your .pro file in the HEADERS-list
- Run qmake every time you add Q_OBJECT to one of your classes or modify your .pro file
(Source: http://www.theirishpenguin.com/2007/07/01/qobject-qmake-and-sadness-undefined-reference-to-vtable/)
Not fulfilling point 2:
You get the “undefined reference to vtable” error if you put your QObject-derived class in the implementation file because moc will not “add” the implementation of the virtual functions to the cpp file. Apparently you can enforce this by adding “#include cpp_file_name.moc” to your “cpp_file_name.cpp” file. Moc will detect this and will generate a “cpp_file_name.moc” file.