Question

I'm trying to compile my QGLWidget object for a simple painting program, but i'm getting some pretty strange errors I can't understand.

/home/gmercer/Qt/Projects/2dPainting/2dPainting/glwidget.cpp:11: error: undefined reference to `QGLFormat::QGLFormat(QFlags<QGL::FormatOption>, int)'
/home/gmercer/Qt/Projects/2dPainting/2dPainting/glwidget.cpp:11: error: undefined reference to `QGLWidget::QGLWidget(QGLFormat const&, QWidget*, QGLWidget const*, QFlags<Qt::WindowType>)'
/home/gmercer/Qt/Projects/2dPainting/2dPainting/glwidget.cpp:11: error: undefined reference to `QGLFormat::~QGLFormat()'

and the list goes on, all pointing at the constructor. Is it something I am not including?

.pro file

#-------------------------------------------------
#
# Project created by QtCreator 2013-11-18T09:16:48
#
#-------------------------------------------------

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = 2dPainting
TEMPLATE = app


SOURCES += main.cpp\
        window.cpp \
    helper.cpp \
    widget.cpp \
    glwidget.cpp

HEADERS  += window.h \
    helper.h \
    widget.h \
    glwidget.h

FORMS +=

glwidget.h

#include <QtOpenGL/QGLWidget>

class Helper;

class GLWidget: public QGLWidget
{
    Q_OBJECT

public:
    GLWidget(Helper *helper, QWidget *parent);

public slots:
    void animate();

protected:
    void paintEvent(QPaintEvent *event);

private:
    Helper *helper;
    int elapsed;
};

glwidget.cpp

#include "glwidget.h"
#include "helper.h"

#include <QTimer>
#include <QtOpenGL/QGLFormat>
#include <QtOpenGL/QGLFunctions>
#include <QtOpenGL/QGLWidget>

GLWidget::GLWidget(Helper *helper, QWidget *parent):
    QGLWidget(QGLFormat(QGL::SampleBuffers), parent),
    helper(helper)
{
    elapsed = 0;
    setFixedSize(200, 200);
    setAutoFillBackground(false);
}

helper.h

#include <QBrush>
#include <QFont>
#include <QPen>
#include <QWidget>

class Helper
{
public:
    Helper();
public:
    void paint(QPainter *painter, QPaintEvent *event, int elapsed);

private:
    QBrush background;
    QBrush circleBrush;
    QFont textFont;
    QPen circlePen;
    QPen textPen;
};
Was it helpful?

Solution

QT       += core gui

Add "opengl" to that list.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top