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:
#include <QOpenGLWidget>
in my custom class, and also add the #include
for glew.h
, I can access the things defined in glew.h
#include <QtWidgets>
in my custom class (which I though would cover QOpenGLWidget
too), then I can't access what is defined in glew.h
and I see "identifier not defined" errors (for example, for glGenVertexArrays
)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
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.