Q_OBJECT throwing 'undefined reference to vtable' error
It is because the unit generated by MOC isn't included in the linking process. Or maybe it isn't generated at all. The first thing I'd do is to put the class declaration in a separate header file, perhaps the build system isn't scanning implementation files.
Another possibility is that the class in question once didn't belong to Qt meta object system (that is, it had no Q_OBJECT or maybe didn't inherit from QObject at all), so qmake needs to be run again in order to create the necessary rules for MOC. The easiest way to force qmake to be run is to make some insignificant changes to the project file to update its timestamp, like adding and then removing some white space. Or, if you're using Qt Creator, then just select “Run qmake” from the project context menu.
Qt C++ Q_OBJECT error undefined reference to vtable
To use the QOBJECT macro in your class you need to extend QObject.
class MyObject: public QObject
{
Q_OBJECT
public:
MyObject (QObject *_parent);
.....
};
Undefined reference to vtable
So, I've figured out the issue and it was a combination of bad logic and not being totally familiar with the automake/autotools world. I was adding the correct files to my Makefile.am template, but I wasn't sure which step in our build process actually created the makefile itself. So, I was compiling with an old makefile that had no idea about my new files whatsoever.
Thanks for the responses and the link to the GCC FAQ. I will be sure to read that to avoid this problem occurring for a real reason.
QObject: Missing vtable link error
You need to include this line at the end of your source file:
#include "MainController.moc"
Alternatively, you can also handle this with your buildsystem, but that is probably the former is easier.
linker error: undefined reference to `vtable of QGLViewer’
You were not running glviewer.h through moc. That's what the error is saying. In your .pro file, change
HEADERS += mainwindow.h \
glviewer.cpp
to
HEADERS += mainwindow.h \
glviewer.h <------
Related Topics
Force to Link Against Unused Shared Library
How to Know If One Shared Library Depends on Another Shared Library or Not
C-Style Strings as Template Arguments
How to Check If C++ Compiler Uses Ieee 754 Floating Point Standard
Sort Array by First Item in Subarray C++
How to Read a Binary File into a Vector of Unsigned Chars
How to Efficiently Display Opencv Video in Qt
Is Inline Assembly Language Slower Than Native C++ Code
How to Monitor a Folder with All Subfolders and Files Inside
System("Command") Produces an Error; But It Works When Invoked Directly from Bash Prompt
Using Input Function in C on Linux, Without Pressing Enter
Q_Object Throwing 'Undefined Reference to Vtable' Error
In C++, Is It Safe/Portable to Use Static Member Function Pointer for C API Callbacks
A Warning - Comparison Between Signed and Unsigned Integer Expressions