开发者

QT OpenGL QGLWidget cannot be found

I am new to Qt and I have problem. I downloaded Qt SDK for Open Source C++ develop开发者_如何学Cment 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?


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

QT += core gui opengl


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


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)


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜