linker error: undefined reference to `vtable of QGLViewer’-Collection of common programming errors

I’m working on a visualization project. It should view a 3d model on a QGLViewer. I have a subclass of QGLViewer defined like this:

class GLViewer : public QGLViewer
{
    Q_OBJECT
public:
    explicit GLViewer(QWidget *parent = 0,const QGLWidget* shareWidget=0, Qt::WFlags flags=0);
protected:
    void initializeGL();
    void resizeGL(int width, int height);
    void paintGL();
signals:
public slots:
};

Implementing the c’tor like this:

GLViewer::GLViewer(QWidget *parent, const QGLWidget* shareWidget, Qt::WFlags flags):
    QGLViewer(parent,shareWidget,flags)
{
}

I’m getting linker error:

glviewer.o: In function `GLViewer::GLViewer(QWidget*, QGLWidget const*, QFlags)':
glviewer.cpp:(.text+0x18): undefined reference to `vtable for GLViewer'
glviewer.cpp:(.text+0x20): undefined reference to `vtable for GLViewer'

EDIT: This is content of .pro file:

QT       += core gui opengl xml

TARGET = qglviewer-test
TEMPLATE = app

LIBS += -lqglviewer-qt4 -lGLU -lGLEW

SOURCES += main.cpp\
        mainwindow.cpp \
        glviewer.cpp

HEADERS  += mainwindow.h \
        glviewer.cpp

FORMS += mainwindow.ui

  1. 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

Originally posted 2013-11-09 21:08:40.