Damir
Damir

Reputation: 56249

QT OpenGL QGLWidget cannot be found

I am new to Qt and I have problem. I downloaded Qt SDK for Open Source C++ development from http://qt.nokia.com/downloads/sdk-windows-cpp, I add C:\QT\2010.05\bin in my PATH. When I start some demo projects it works, but when I create same project (I create a new project and copy the source code from the demo) it shows an error like "QGLWidget cannot be found" (I need to create an OpenGL project). Do I need to add anything else to my PATH? Does anybody know what could be the problem?

Upvotes: 10

Views: 28547

Answers (5)

Jianping
Jianping

Reputation: 1

It should be:

find_package(Qt6 REQUIRED COMPONENTS OpenGLWidgets) 
target_link_libraries(mytarget private Qt::OpenGLWidgets)

Upvotes: 0

iaskdumbstuff
iaskdumbstuff

Reputation: 433

For Qt 6+, add QT += openglwidgets instead of opengl, as per the documentation.

Upvotes: 4

László Papp
László Papp

Reputation: 53215

From Qt 6, you need to use cmake to access this. This is how you would do it:

find_package(Qt6 REQUIRED COMPONENTS OpenGL) 
target_link_libraries(mytarget Qt::OpenGL)

Upvotes: 3

Patrice Bernassola
Patrice Bernassola

Reputation: 14446

You need to add the OpenGL module in your project file (.pro) as explain in the doc: http://doc.qt.io/qt-5/qtopengl-index.html#details

Upvotes: 8

Cory Klein
Cory Klein

Reputation: 55840

Edit your .pro file and add opengl as an option to QT:

QT += core gui opengl

Upvotes: 10

Related Questions