Mihai8
Mihai8

Reputation: 3147

Settings errors in Qt project with OpenGL

In the project that use OpenGL in Qt I use in protected method initializeGL() the statement

 qglClearColor(qtPurple.dark());

Follows errors occurs in the building project:

 ‘qtPurple’ was not declared in this scope
 ‘qglClearColor’ was not declared in this scope

The files that is included is:

 #include <QtGui>
 #include <QtOpenGL>
 #include <QtGui/QColor>

In the .pro file is present

QT       += core gui, opengl

Where are the mistakes that cause these errors?

Upvotes: 0

Views: 1316

Answers (2)

prehistoricpenguin
prehistoricpenguin

Reputation: 6326

  1. Add #include <QtOpenGL/QGLWidget> in your head file.And Your class should inherit QGLWidget.

  2. It seems that you have not declared the variable qtPurple,so check your head file,if not exist,just declare it[like this:QColor qtPurple;].

Upvotes: 1

Sergey
Sergey

Reputation: 8238

QGLClearColor is a non-static member of QGLWidget. So first you must include <QGLWidget> to your widget header file and inherit your widget from QGLWidget. Then you will be able to call it in methods of your widget. You get was not declared in this scope error because qglClearColor is in QGLWidget scope.

Alternatively, you can call it as regular method of your widget object.

And what is qtPurple? It seems that it's not a part of Qt.

Upvotes: 2

Related Questions