如何在运行时确定Qt 5中QtWebEngine使用的铬版本? [英] How to determine which chromium version is used by QtWebEngine in Qt 5 at run-time?

查看:111
本文介绍了如何在运行时确定Qt 5中QtWebEngine使用的铬版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在Qt 5中找到任何函数来确定 QtWebEngine 使用的是哪个版本的铬.

I couldn't find any function in Qt 5 to determine which chromium version is used by QtWebEngine.

我不想在代码中对Chrome版本进行硬编码,因为我经常更新应用程序,并且每个版本中的Chrome版本通常都会更改.而且Qt向后兼容,可以在不更新我的应用程序的情况下对其进行更新.

I don't want to hard-code the chromium version in my code because I frequently update my application and the chromium version is usually changed in each version. And also Qt is backward-compatible and it is possible to update it without updating my application.

推荐答案

除了查看

There is no direct solution but looking at the source code You can see that it is used to set the default user agent:

std::string ContentBrowserClientQt::getUserAgent()
{
    // Mention the Chromium version we're based on to get passed stupid UA-string-based feature detection (several WebRTC demos need this)
    return content::BuildUserAgentFromProduct("QtWebEngine/" QTWEBENGINECORE_VERSION_STR " Chrome/" CHROMIUM_VERSION);
}

因此可以从该数据中提取它:

So it can be extracted from that data:

QString version;
QString user_agent = QWebEngineProfile::defaultProfile()->httpUserAgent();
for(const QString & text : user_agent.split(" ")){
    if(text.startsWith(QStringLiteral("Chrome/"))){
        version = text.mid(QStringLiteral("Chrome/").length());
    }
}
qDebug().noquote()<< "Qt version:" << QT_VERSION_STR << "chromium version:" << version;

输出:

Qt version: 5.14.2 chromium version: 77.0.3865.129

这篇关于如何在运行时确定Qt 5中QtWebEngine使用的铬版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆