Farzad
Farzad

Reputation: 1939

Custom QOpenGLWidget and GLEW include

Sorry if this is a very basic question, but I'm confused:
I'm using Visual Studio and I'm creating a custom QOpenGLWidget class (by inheriting from the base class), and my problem is as follows:

Can someone please tell me what I'm missing here? I'm guessing that including what I only need (#include <QOpenGLWidget>) is better than a whole lot of stuff in <QtWidgets>, but why should it prevent me from accessing what is defined in glew.h?

Any help is appreciated

Upvotes: 0

Views: 316

Answers (1)

Nicol Bolas
Nicol Bolas

Reputation: 474436

You cannot simultaneously include Qt's OpenGL wrappers and most OpenGL loading library headers. Different .cpp files can include different headers, but the same .cpp cannot. So you're going to have to pick what you want to use: GLEW or Qt's OpenGL wrapper.

The reason this doesn't work is because loaders generally use include guards that prevent you from accidentally including <GL/gl.h> or similar headers. Loading libraries tend to be exclusive, since they are often defining the same symbols that other OpenGL headers would. And if they didn't keep you from doing that, you could get multiply-defined-symbol errors if you try to include both.

Qt's OpenGL wrapper is itself a loading library. So it does the same exclusion trick, defining the include guards that GLEW and other loaders would use. As such, you can't use both in the same .cpp file.

Upvotes: 1

Related Questions