在 Qt6 中,QtWebEngine
模块作为对 Chromium 的封装,提供了强大的网页渲染能力。然而,官方发布的预编译版本通常不包含专有编解码器(proprietary codecs)支持,例如对 H.264、MP3 的解码。
为了获得完整的多媒体功能,我们可以使用 vcpkg 从源代码编译 Qt6 的 qtwebengine
模块,并启用 proprietary-codecs
选项。
本文将详解整个编译过程,特别是如何解决构建过程中可能出现的 Python 版本兼容问题。
操作系统:Windows 10
编译器:Visual Studio 2022 Community(版本:17.13.6)
如果安装的 Visual Studio 2022 版本是 17.14.0,推荐回滚到版本 17.13.6
xxxxxxxxxx
git clone https://github.com/microsoft/vcpkg.git
cd vcpkg
bootstrap-vcpkg.bat
xxxxxxxxxx
vcpkg.exe install --editable qtwebengine[proprietary-codecs] --x-buildtrees-root=D:/b
说明:
--editable
允许修改源代码(例如后期自定义补丁)
--x-buildtrees-root=D:/b
指定构建输出路径,避免默认路径过长或空间不足
在构建过程中,你可能会遇到如下错误:
xxxxxxxxxx
[38130/40113] ACTION //components/resources/ssl/ssl_error_assistant:make_ssl_error_assistant_protobuf(//build/toolchain/win:x64)
FAILED: gen/components/resources/ssl/ssl_error_assistant/ssl_error_assistant.pb
D:/_build/qtwebengine/x64-windows-venv/Scripts/python.exe ../../../../../src/here-src-6-fc421f1193.clean/src/3rdparty/chromium/components/resources/ssl/ssl_error_assistant/gen_ssl_error_assistant_proto.py -w -i ../../../../../src/here-src-6-fc421f1193.clean/src/3rdparty/chromium/components/resources/ssl/ssl_error_assistant/ssl_error_assistant.asciipb -d gen/components/resources/ssl/ssl_error_assistant -o ssl_error_assistant.pb -p pyproto -p pyproto/components/security_interstitials/content/
ninja: build stopped: subcommand failed.
FAILED: src/core/Debug/AMD64/QtWebEngineCore.stamp src/core/Debug/AMD64/obj/tools/v8_context_snapshot/v8_context_snapshot.stamp src/core/Debug/AMD64/QtWebEngineCore D:/b/qtwebengine/x64-windows-dbg/src/core/Debug/AMD64/QtWebEngineCore.stamp D:/b/qtwebengine/x64-windows-dbg/src/core/Debug/AMD64/obj/tools/v8_context_snapshot/v8_context_snapshot.stamp D:/b/qtwebengine/x64-windows-dbg/src/core/Debug/AMD64/QtWebEngineCore
C:\WINDOWS\system32\cmd.exe /C "cd /D D:\b\qtwebengine\x64-windows-dbg\src\core && D:\vcpkg\downloads\tools\ninja\1.12.1-windows\ninja.exe -C D:/b/qtwebengine/x64-windows-dbg/src/core/Debug/AMD64 QtWebEngineCore"
ninja: build stopped: subcommand failed.
推荐卸载掉电脑上自己安装的所有 Python
检查系统环境变量,把 PATH 下无关的环境变量清理一下
另外,使用 vcpkg 编译 qtwebengine 不需要 修改系统的区域和 Unicode 编码
会自动编译 debug 和 release 版本,花了4小时,最后 build 文件夹大小 82.7 G
检查 C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build
需要有 vcvars64.bat 文件
检查 C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Redist\MSVC
只包含 14.42.34433 和 v143 文件夹
运行 C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Visual Studio 2022\Visual Studio Tools\VC\x64 Native Tools Command Prompt for VS 2022
输入 cl
输出 用于 x64 的 Microsoft (R) C/C++ 优化编译器 19.43.34810 版
检查下 C:\Program Files (x86)\Windows Kits\10\bin
包含 10.0.22621.0 文件夹,不包含 10.0.26100.0 文件夹
vcpkg 编译时需要下载很多文件(3个G)
我上传到百度云(https://pan.baidu.com/s/1VrkneLtX3PyhAKb2pQMMyw?pwd=2v4k)
方便代理网速慢的同学
编译前把 downloads 文件夹替换 vcpkg 文件夹内的 downloads 就可以了