Reputation: 711
I'm trying to write a C++ application that uses QOpenGLWidget, but Qt Creator gives a "'QOpenGLWidget' file not found" error on this line:
#include <QOpenGLWidget>
The documentation says QOpenGLWidget was introduced in Qt 5.4, and I believe I am running Qt 5.12.1; qmake --version
gives:
QMake version 3.1
Using Qt version 5.12.1 in /home/oreilly/Qt5.12.1/5.12.1/gcc_64/lib
Moreover, in the Qt Creator menu Tools -> Options... -> Kits also indicates Qt 5.12.1. And Qt Creator allows me to use #include <QOpenGLWindow>
(also introduced in Qt 5.4 along with QOpenGLWidget), compile and link the OpenGL application without error.
What am I doing wrong? Where is QOpenGLWidget?
Upvotes: 2
Views: 5537
Reputation: 21
At least for Qt 6 for the QOpenGLWidget Class one wants:
qmake: QT += openglwidgets
Source: https://doc.qt.io/qt-6/qopenglwidget.html
For the QOpenGLWindow Class one wants:
qmake: QT += opengl
Source: https://doc.qt.io/qt-6/qopenglwindow.html
Upvotes: 1
Reputation: 73081
QOpenGLWidget
is not part of the main QtCore/QtWidgets libraries; rather it is part of a separate (QtOpenGL) library whose headers are in a directory that is not part of the Qt include-path by default.
Fortunately, it's easy to add QtOpenGL's headers to the include-path; just insert the following line into your .pro file:
QT += opengl
... and then run qmake
to update your Makefile/Project file, and you should be able to compile using the OpenGL classes.
Upvotes: 5