Qt WebEngine 平台注意事项

从源代码构建 Qt WebEngine

静态构建不被支持。

The requirements for building Qt modules from source are listed separately for each supported platform:

此外,需要以下工具为构建 Qt WebEngine 模块:

所有平台

On all platforms, the following tools are required at build time:

  • C++20 compiler support
  • CMake 3.19 or newer
  • Python 3 with html5lib library
  • Bison, Flex
  • GPerf
  • Node.js version 14 or later

Windows

在 Windows,需要以下额外工具:

  • Visual Studio 2019 or later, or clang-cl version 10 or later
  • ATL (活动模板库),通常包括在 Visual Studio 安装中
  • Windows 11 SDK version 10.0.22621.0 or later

注意: It is not recommended to use tools from msys2 or cygwin to build Qt WebEngine as it may result in build errors.

Linux

On Linux, Clang or GCC version 9 or later is required.

Qt WebEngine 要求 pkg-config 以检测其大多数依赖。以下 pkg-config 文件要求:

  • dbus-1
  • fontconfig

若 Qt 被配置为 xcb ,以下 pkg-config 文件也是必需的:

  • libdrm
  • xcomposite
  • xcursor
  • xi
  • xrandr
  • xscrnsaver
  • xtst

macOS

在 macOS,需要以下:

  • macOS 10.14 or later
  • Xcode 12.0 or later
  • macOS 11 SDK or later

注意: 无法为 macOS 的 32 位模式构建 Qt WebEngine (使用 macx-clang-32 mkspec ).

使用早期 Qt 版本构建 Qt WebEngine

Building Qt WebEngine with earlier Qt versions (down to the last LTS version) is supported. It means that Qt WebEngine 6.4 can be built with Qt 6.2.x, Qt 6.3.x, and Qt 6.4.

要使用早期 Qt 版本构建 Qt Webengine:

  1. 下载 qtwebengine 源代码。
  2. 从早期 Qt 版本运行 qmake && make (&& make install) .

Mac APP 商店兼容性

Applications using Qt WebEngine are not compatible with the Mac App Store, because:

  • The Chromium part of the code uses several private API methods, which are prohibited by the App Store.
  • Applications submitted to the App Store must be code-signed with the App Sandbox feature enabled. The App Sandbox feature interferes with Chromium's own sandbox initialization, which results in Chromium not being properly initialized. This also ties in with the private API usage. Furthermore, standalone Chromium itself is not officially tested with the App Sandbox enabled, and even if work is done to bypass the App Store's restrictions, that would not guarantee correct behavior of the library.

支持带双 GPU 的 MacBook macOS Airplay

To make Qt WebEngine work correctly when streaming to an AppleTV from a MacBook that supports GPU switching, it is important to add the NSSupportsAutomaticGraphicsSwitching option to the application Info.plist file, with the value set to YES . Otherwise rendering issues might occur when creating new web engine view instances after Airplay is switched on or off.

默认支持 QSurfaceFormat OpenGL Profile (配置文件)

If a new default QSurfaceFormat with a modified OpenGL profile has to be set, it should be set before the application instance is declared, to make sure that all created OpenGL contexts use the same OpenGL profile.

On macOS, if the default QSurfaceFormat is set after the application instance, the application will exit with qFatal (), and print a message that the default QSurfaceFormat should be set before the application instance.

沙盒支持

Qt WebEngine 为 Chromium 渲染过程提供开箱即用的沙盒支持。

在 Linux,注意以下限定:

  • 内核必须支持匿名名称空间特征 (内核版本 3.8 或更高版本)。不管怎样,在 Debian、Ubuntu 且其它 Debian 派生分发,此特征是关闭的默认情况下。可以打开它通过设置 /proc/sys/kernel/unprivileged_userns_clone to 1.
  • 内核必须支持 seccomp-bpf 特征 (内核版本 3.5 或更高版本)。
  • Setuid 沙盒不受支持,因此被禁用。

要明确禁用沙盒,使用以下选项之一:

  • 设置 QTWEBENGINE_DISABLE_SANDBOX 环境变量到 1。
  • 传递 --no-sandbox 命令行自变量,给用户应用程序可执行文件。
  • Set QTWEBENGINE_CHROMIUM_FLAGS to --no-sandbox .

更多信息,见 使用命令行参数 .

Docker 环境下的内存需求

当在 Docker 容器中运行 Qt WebEngine 范例并浏览内容繁重站点时,可能报告 BUS 错误 (SIGBUS)。通常,这是由于 Docker 运行过小内存空间 (譬如 64MB) 容器导致的。要修复此问题,增加内存空间大小。

可访问性和性能

Qt WebEngine enables accessibility support for web pages when the following conditions are met:

  • Qt Core is configured and built with accessibility support enabled.
  • The QPA plugin is notified by the operating system that accessibility should be activated. This happens for example when using a screen reader application on Windows or VoiceOver on macOS.

On some old Linux configurations, accessibility can cause a significant slowdown on large HTML pages.

Because of that, Qt WebEngine accessibility support can be disabled on Linux, by setting the QTWEBENGINE_ENABLE_LINUX_ACCESSIBILITY environment variable to 0.

Windows 全屏应用程序中的弹出窗口

Because of a limitation in the Windows compositor, applications that show a fullscreen web engine view will not properly display popups or other top-level windows. The reason and workaround is described in 基于 OpenGL 的窗口全屏 .

Windows Application Manifest

A manifest is an XML file that is read when the program starts and informs Windows how to run the program. Some Qt WebEngine features may require adding a manifest file for the user application to work correctly on Windows.

The following snippets show the manifest file's structure and how to embed it into the program.

注意: These code snippets are taken from the WebEngine Quick 纳米浏览器 范例。

The manifest file defines which Windows versions the application supports. httpUserAgent needs this information to report the correct Windows version.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
    <application>
    <!--The ID below indicates application support for Windows Vista -->
    <supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
    <!--The ID below indicates application support for Windows 7 -->
    <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
    <!--The ID below indicates application support for Windows 8 -->
    <supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
    <!--The ID below indicates application support for Windows 8.1 -->
    <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
    <!--The ID below indicates application support for Windows 10/11 -->
    <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
    </application>
</compatibility>
</assembly>
					

To embed the file into the executable, add it to the sources:

    ...
qt_add_executable(quicknanobrowser
    main.cpp
    utils.h
)
if(WIN32)
    set_property(
        TARGET quicknanobrowser
        APPEND PROPERTY
            SOURCES quicknanobrowser.exe.manifest)
endif()
    ...
					

更多信息,见 Application manifest documentation page .