PDA

View Full Version : QGLWidget libraries?



xleniz
8th June 2012, 13:09
What is wrong, I added QT += core gui opengl, I'm getting spammed with error:


/home/marcus/untitled1/main.cpp:-1: error: undefined reference to `vtable for GLWidget'


Here's code:



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

class GLWidget :public QGLWidget {
Q_OBJECT

public:
GLWidget(QWidget *parent = 0);
protected:
virtual void initializeGL();
virtual void resizeGL( int width, int height );
virtual void paintGL();
virtual void keyPressEvent( QKeyEvent *e );
virtual void timeOut();

};

GLWidget::GLWidget(QWidget *parent) : QGLWidget(parent) {

}

void GLWidget::initializeGL() {
glDisable(GL_TEXTURE_2D);
glDisable(GL_DEPTH_TEST);
glDisable(GL_COLOR_MATERIAL);
glEnable(GL_BLEND);
glEnable(GL_POLYGON_SMOOTH);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glClearColor(0, 0, 0, 0);
}

void GLWidget::resizeGL(int w, int h) {
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

void GLWidget::paintGL() {
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1,0,0);
glBegin(GL_POLYGON);
glVertex2f(0,0);
glVertex2f(100,500);
glVertex2f(500,100);
glEnd();
}

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
GLWidget gl;
gl.show();
return a.exec();
}

wysota
8th June 2012, 21:30
Add #include "main.moc" in line #50 and rerun qmake. Then start searching the forum on why it works.