Qt WebEngine 平颱注意事項

從源代碼構建 Qt WebEngine

靜態構建不被支持。

分彆列齣從源代碼構建 Qt 5 模塊的要求,對於各個支持平颱:

此外,需要以下工具為構建 Qt WebEngine 模塊:

跳過 Qt WebEngine 構建的測試位於 qtwebengine 存儲庫,在 tools\qmake\mkspecs 子目錄。可以找到它們通過搜索 skipBuild .

所有平颱

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

  • Python 2.7.5 或更高版本。不支持 Python 3。
  • Bison, Flex
  • GPerf
  • Node.js version 8 or later (version 12 or later is recommended)

Windows

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

  • Visual Studio 2017 version 15.8 or later, or clang-cl version 8 or later
  • ATL (活動模闆庫),通常包括在 Visual Studio 安裝中
  • Windows 10 SDK version 10.0.19041 or later

Qt WebEngine 隻能在帶有 x64 位工具鏈的 64 位 Windows 中進行構建。為構建用於 x86 應用程序的 Qt WebEngine,需要采用 Visual Studio 2017 x64 to x86 交叉編譯工具鏈來配置和編譯 Qt。可以在命令行中設置此工具鏈,通過運行 vcvarsall.bat amd64_x86 .

Linux

在 Linux,需要 Clang 或 GCC 第 5 版或更高版本。支持配置 linux-g++ , linux-clang and linux-clang-libc++

Qt WebEngine 要求 pkg-config 以檢測其大多數依賴。以下 pkg-config 文件要求:

  • dbus-1
  • fontconfig

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

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

進一步,開發包為 khr and libcap 需要安裝。

macOS

在 macOS,需要以下:

  • macOS 10.13 或更高版本
  • Xcode 10.0 或更高版本
  • macOS 10.13 SDK 或更高版本

注意: 無法為 macOS 的 32 位模式構建 Qt WebEngine (使用 macx-clang-32 mkspec ).

注意: Universal debug or debug-and-release builds of Qt WebEngine on macOS are not supported in Qt 5 due to memory constraints of the build toolchain. Use the configure options -force-debug-info and -separate-debug-info for a build that can be used with a debugger.

使用早期 Qt 版本構建 Qt WebEngine

支持采用早期版本 (到最新 LTS 版本) 的 Qt 構建 Qt WebEngine。意味著可以采用 Qt 5.12.x、Qt 5.14.x 及 Qt 5.15構建 Qt WebEngine 5.15。

要使用早期 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 到 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 for the issue can be found at 基於 OpenGL 的窗口全屏 and QWindowsWindowFunctions::setHasBorderInFullScreen .