1、检测显卡驱动是否存在,不存在的情况,再去使用Qt::AA_UseSoftwareOpenGL选项
bool _isNotInstalledVideoDriver() {
QProcess *wmic = new QProcess();
wmic->setProcessChannelMode(QProcess::MergedChannels);
QObject::connect(wmic, &QProcess::readyReadStandardOutput, [wmic]() {
QTextStream stream(wmic->readAllStandardOutput());
QString s;
while (stream.readLineInto(&s)) {
QString line = s.trimmed();
if (line.isEmpty())
continue;
if (line.startsWith("InfFilename", Qt::CaseSensitive)) {
infName = line.split("=")[1];
} else if (line.startsWith("Name", Qt::CaseSensitive)) {
drvName = line.split("=")[1];
}
}
});
wmic->start("wmic path win32_videoController get InfFilename,name /format:list");
wmic->waitForFinished();
return infName.startsWith("display.inf");
}
2、检测opengl版本
QOpenGLContext ctx;
ctx.create();
QSurfaceFormat format = ctx.format();
auto major = format.majorVersion();
auto minor = format.minorVersion();
if (major < 2) {
QCoreApplication::setAttribute(Qt::AA_UseOpenGLES, false);
QCoreApplication::setAttribute(Qt::AA_UseSoftwareOpenGL, true);
}
3、QWebengine显示黑屏的解决
qputenv("QMLSCENE_DEVICE", "softwarecontext");
注意:这些Attribute,要在QGuiApplication 构造之前设置才会生效!!!
该博客介绍了如何检查显卡驱动是否存在,并在缺失时使用Qt的软件OpenGL选项。同时,它展示了如何检测OpenGL版本,并在版本过低时切换到软件渲染。最后,针对QWebEngine显示黑屏的问题,提出了设置QMLSCENE_DEVICE环境变量为'softwarecontext'的解决方案。注意,这些设置需要在QGuiApplication构造之前完成。
3099

被折叠的 条评论
为什么被折叠?



