Undefined link to vtable, Qt on Linux

I tried to compile the Qt program and OpenGL in Code :: Blocks in Ubuntu 10.04. I get the link "undefined to" vtable for GLWidget "

#ifndef _GLWIDGET_H
#define _GLWIDGET_H

#include <QtOpenGL/QGLWidget>
#include "stdlib.h"

class GLWidget : public QGLWidget {

    Q_OBJECT // must include this if you use Qt signals/slots

public:
    GLWidget(QWidget *parent = 0);
    ~GLWidget();
protected:
    void initializeGL();
    void resizeGL(int w, int h);
    void paintGL();
    void keyPressEvent(QKeyEvent *event);
};

#endif  /* _GLWIDGET_H */

I borrowed this guy's code to find out if it works because my work does not work for the same reason. Code

And here is GLWidget.cpp:

#include <QtGui/QMouseEvent>
#include "glwidget.h"

GLWidget::GLWidget(QWidget *parent) : QGLWidget(parent) {
    setMouseTracking(true);
}

GLWidget::~GLWidget()
{
}

void GLWidget::initializeGL() {
   ...
}

void GLWidget::resizeGL(int w, int h) {
   ...
}

void GLWidget::paintGL() {
    ...
}

void GLWidget::keyPressEvent(QKeyEvent* event) {
    ...
    }
}

I removed the code from the GL part so that it is shorter. If you need it, I can always publish it.

#include <QtGui/QApplication>
#include <QtOpenGL/QGLWidget>
#include "glwidget.h"

int main(int argc, char *argv[]) {

    QApplication app(argc, argv);

    GLWidget window;
    window.resize(800,600);
    window.show();

    return app.exec();
}
+5
source share
5 answers

In the project.pro file add

QT += opengl

So, he knows that he must reference GL libraries.

+5
source

Clean up the project and run qmake.

+3

'undefined "vtable GLWidget", , , - GLWidget .

, , moc ( QT, ).

+1

Q_OBJECT moc_.

, :

  • $qmake filename.pro
  • $make
+1

Q_OBJECT .

QT Creator, Linux.

For me, the solution was to delete the folder YourProjectName-build-desktop, which is at the same level as your project directory. Then, when I built the project from QT Creator, it magically worked.

+1
source

All Articles