Trying to build OpenGl widget, but getting linking errors.
-
glwidget.h
#ifndef GLWIDGET_H
#define GLWIDGET_H#include <QtOpenGL/QGLWidget>
class GLWidget : public QGLWidget {
Q_OBJECT
public:
GLWidget(QWidget *parent = 0);
~GLWidget();
QSize sizeHint() ;protected:
void initializeGL();
void paintGL();
void resizeGL(int width, int height);
};#endif // GLWIDGET_H
glwidget.cpp
#include "glwidget.h"
#include "ui_glwidget.h"GLWidget::GLWidget(QWidget *parent) : QGLWidget(parent) {
}GLWidget::~GLWidget(){ }
void GLWidget::initializeGL() {
glClearColor(0.0, 0.0, 0.0, 0.0);
glEnable(GL_DEPTH_TEST);}
QSize GLWidget::sizeHint(){
return QSize(400, 400);
}void GLWidget::paintGL(){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(-1.5f,0.0f,-6.0f);
glBegin(GL_TRIANGLES);
glVertex3f( 0.0f, 1.0f, 0.0f);
glVertex3f(-1.0f,-1.0f, 0.0f);
glVertex3f( 1.0f,-1.0f, 0.0f);
glEnd();
}void GLWidget::resizeGL(int w, int h){
QGLWidget::resize(w,h);
}I keep getting LNK2019 and LNK2001 . I am assuming it is because I did not reimpliment all of the virtual functions and slots. Anythoughts?
-
Hi and welcome to DevNet,
First thing, please enclose your code with Code tags (one @ at the beginning and one at the end), that will make the post much more readable.
Then to your problem, could you post the error you are getting ?
-
Which libraries/symbols is it complaining are missing?
-
All of the errors look something like this.
glwidget.obj:-1: error: LNK2001: unresolved external symbol "public: virtual class QPaintEngine * __thiscall QGLWidget::paintEngine(void)const " (?paintEngine@QGLWidget@@UBEPAVQPaintEngine@@XZ)
-
Do you have
@QT += opengl@in your .pro file ?