I am new to using OpenGL with Qt Creator and I have been playing around with the information I got from various tutorials. However, I never was able to find out where the OpenGL function definitions actually are!
I was thinking that when I linked the opengl module to the qmake file like this:
QT += core gui opengl
the OpenGL stuff was included, but then I thought again when I was reading about the QGLWidget.
So where does the OpenGL API become included into my code?
P.S. My OS is Windows 7 and I my graphics card is AMD Radeon HD 6250 Graphics.
The QT variable is used to include Qt modules into your project. By adding opengl you’re adding the Qt OpenGL module which contains Qt code that uses OpenGL (and links to it). If by “include” you mean link, than the OpenGL module of Qt (libQtOpenGL.so) links the various OpenGL libraries. Also, the Qt module includes the headers of the Qt OpenGL module which in turn includes OpenGL headers.
The OpenGL headers and the OpenGL libraries are wherever your OS keeps those. Your project knows where those are because of the Qt mkspecs for your platform, whatever it is. In the mkspecs, include paths and link paths are already included.
For instance, now I’m on a Mac OS X, and Qt mkspecs are installed in /usr/local/Qt4.8/mkspecs. Here I have all the platform descriptions, under common you can find mac.conf, which is a part of the description of my platform. Inside it you can see:
This information is used when Qt Creator (qmake) is asked to produce a Makefile for any application. This way your application knows where to find the headers for OpenGL. Your project will automatically add that to the include paths only when you add the opengl module.
As another example, this is part of the definition for the Linux platform:
I suppose you can understand on your own what this means 😉
So to answer your question: the include paths and the link paths to the OpenGL libraries are included into the Makefile qmake produces for your application taking the information stored in the mkspec file which is located somewhere in your system. The actual OpenGL headers and libraries are located in a default location in your system, and this has nothing to do with Qt itself. You might need to include the headers in your source code if you use OpenGL libraries directly (or you might not need, it depends), but the include paths should already be provided by your mkspec files.
EDIT: Look what happens automatically when adding the opengl module: this is the command line Qt Creator uses to compile a C++ file without the opengl module (on Mac):
now this is what happens after adding it:
Your project has been told where to look for the OpenGL headers.