Qt5 Boxes示例编译失败

在研究Qt的GraphicsView下使用OpenGL的事情, 一个很经典的例子就是Qt5的Boxes示例(在Qt6里面没有了). 但是Qt5的Boxes在Windows下会编译失败. 经过网上查找, 需要这么修改:

  • 注释掉qtConfig(...)
  • 增加LIBS += -lopengl32LIBS += -lopengl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
QT += opengl widgets
requires(qtConfig(combobox))

#qtConfig(opengles.|angle|dynamicgl): error("This example requires Qt to be configured with -opengl desktop")

HEADERS += 3rdparty/fbm.h \
glbuffers.h \
glextensions.h \
gltrianglemesh.h \
qtbox.h \
roundedbox.h \
scene.h \
trackball.h
SOURCES += 3rdparty/fbm.c \
glbuffers.cpp \
glextensions.cpp \
main.cpp \
qtbox.cpp \
roundedbox.cpp \
scene.cpp \
trackball.cpp

RESOURCES += boxes.qrc
LIBS += -lopengl32

#LIBS += -lopengl
# install
target.path = $$[QT_INSTALL_EXAMPLES]/widgets/graphicsview/boxes
INSTALLS += target

另外想起来, QCustomPlot也是需要这么修改的, QtChart好像也是类似的修改方法.