简体   繁体   English

如何在 Qt 和 VIsual Studio 中创建 OpenGL 小部件?

[英]How to create a OpenGL widget in Qt and VIsual Studio?

I'm trying to create a OpenGL widget using Qt 6.4 and VStudio 2022 , i have enable the Qt OpenGL widget under the modules, but i still getting a lot of compile errors:我正在尝试使用Qt 6.4VStudio 2022创建一个OpenGL小部件,我在模块下启用了Qt OpenGL小部件,但我仍然遇到很多编译错误:

LNK2019 unresolved external symbol "__declspec(dllimport) public: __cdecl QOpenGLWidget::QOpenGLWidget(class QWidget *,class QFlags<enum Qt::WindowType>)" (__imp_??0QOpenGLWidget@@QEAA@PEAVQWidget@@V?$QFlags@W4WindowType@Qt@@@@@Z) referenced in function "public: void __cdecl Ui_MainWindowClass::setupUi(class QMainWindow *)" (?setupUi@Ui_MainWindowClass@@QEAAXPEAVQMainWindow@@@Z)

I'm testing in a 'clean' project containing nothing more than a OpenGlWidget added trough QT Designer.我正在一个“干净”的项目中进行测试,其中仅包含一个OpenGlWidget Designer 添加的 OpenGlWidget。

The includes i have added:我添加的包括:

#include <QtWidgets>
#include <QtOpenGL>

My project configuration:我的项目配置:

在此处输入图像描述

I have also tried adding, into Linker -> General -> Additional Library directories :我也尝试将其添加到Linker -> General -> Additional Library directories

D:\Qt\6.4.0\msvc2019_64\lib;

And at Linker -> Input -> Additional Dependencies :Linker -> Input -> Additional Dependencies处:

Qt6OpenGL.lib

But i continue getting the same errors.但我继续收到同样的错误。

I have installed everything in the Qt Maintenance tool , what i'm missing?我已经安装了Qt Maintenance tool中的所有内容,我缺少什么?

QOpenGLWidget has been moved to Qt OpenGL Widgets module. QOpenGLWidget已移至 Qt OpenGL Widgets 模块。 You must to link against both Qt6OpenGL.lib and Qt6OpenGLWidget.lib .您必须同时链接Qt6OpenGL.libQt6OpenGLWidget.lib

https://doc.qt.io/qt-6/opengl-changes-qt6.html#the-qopenglwidgets-class https://doc.qt.io/qt-6/opengl-changes-qt6.html#the-qopenglwidgets-class

Which help from Qt Forum, I found that these errors were being caused because I was missing adding the openglwidgets module into the project.求助Qt论坛,我发现这些错误是因为我没有在项目中添加openglwidgets模块。

After setting Qt Modules to core;gui;widgets;opengl;openglwidgets it compiled successfully.Qt Modules设置为core;gui;widgets;opengl;openglwidgets后编译成功。

It strange that the module openglwidgets is missing in the plugin window of Qt Modules , should be reported as a bug/missing?奇怪的是, Qt Modules openglwidgets应该报告为错误/缺失吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM