P
P
Paul2017-01-03 18:23:53
Qt
Paul, 2017-01-03 18:23:53

How to enable OpenGL in Qt Creator?

Created a Qt Widgets application, created a drawing class called MainScene, in this class overridden three methods of the QGLWidget base class: initializeGL(), resizeGL(int w, int h) and paintGL().
This is how the code in mainscene.h looks like:

#ifndef MAINSCENE_H
#define MAINSCENE_H

#include <QGLWidget>

class MainScene : public QGLWidget
{
    protected:
    void initializeGL();
    void resizeGL(int w, int h);
    void paintGL();
public:
    MainScene(QWidget* parent = 0);
};

#endif // MAINSCENE_H

This is how the code in mainscene.cpp looks like:
#include "mainscene.h"

MainScene::MainScene(QWidget *parent)
{
}

void MainScene::initializeGL() {
    glClearColor(1.0, 1.0, 1.0, 1.0); // Тут ошибка!
}

void MainScene::resizeGL(int w, int h) {
}

void MainScene::paintGL() {
}

The error looks like this: D:\qt_pro\opengl_test_4\mainscene.cpp:11: error: undefined reference to `[email protected]' collect2.exe:-1: error: error: ld returned 1 exit status I
wrote in the .pro file: QT += core gui opengl I think that the problem is the lack of libraries, the question is which ones and how to include them. Thank you very much in advance :)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
J
Julia, 2017-01-04
@Julila

rucodes.com/opengl-microsoft-visual-studio-c.html
Check in the project settings if there are already libs for openGl

K
Kirixo, 2019-12-26
@Kirixo

you need to write in the .pro file LIBS += -lopengl32

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question