Qt6使用opengl

1.使用qmloscilloscope工程

2.main函数里

bool openGLSupported = QQuickWindow::graphicsApi() == QSGRendererInterface::OpenGLRhi;
if (!openGLSupported) {
qWarning() << "OpenGL is not set as the graphics backend, so AbstractSeries.useOpenGL will not work.";
qWarning() << "Set QSG_RHI_BACKEND=opengl environment variable to force the OpenGL backend to be used.";
}

QQuickWindow::graphicsApi() 默认返回的是4(Direct3D11),故会报waring

3.解决

可以增加环境变量

 或者增加代码(二选一都可以,两个枚举的值是一样的):

QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGL);
QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGLRhi);

4.关于Chart里线的更新

QLineSeries and QScatterSeries(或者他们的qml类型),提供属性useOpenGL决定是否使用opengl。

当图表包含任何使用 OpenGL 绘制的系列时,将为 ChartView 节点创建一个额外的透明子节点。加速的系列不会在 ChartView 节点上绘制,而是绘制在子节点上。

5.QSG_RENDER_TIMING

如果将此环境变量设置为1,则会打印程序的渲染速度信息

 

posted @ 2025-05-31 23:56  朱小勇  阅读(112)  评论(0)    收藏  举报