Qt WebView

Qt WebView lets you display web content inside a QML application. To avoid including a full web browser stack, Qt WebView uses native APIs where appropriate.

This is useful on mobile platforms, such as Android and iOS . On iOS, policies dictate that all web content is displayed using the operating system's web view.

On Windows and Linux, Qt WebView depends on the Qt WebEngine 模块渲染内容。

On macOS, the system web view is used in the same manner as iOS.

先决条件

To make the Qt WebView module function correctly across all platforms, it's necessary to call QtWebView::initialize() before creating the QGuiApplication instance and before window's QPlatformOpenGLContext is created.

使用模块

QML API

模块的 QML 类型是可用的透过 QtWebView 导入。要使用类型,添加以下 import 语句到 .qml 文件:

import QtWebView
					

C++ API

使用 Qt 模块的 C++ API 要求直接 (或透过其它依赖) 链接到模块库。几个构建工具对此有专用支持,包括 CMake and qmake .

构建采用 CMake

使用 find_package() 命令定位所需模块组件在 Qt6 包:

find_package(Qt6 REQUIRED COMPONENTS WebView)
target_link_libraries(mytarget PRIVATE Qt6::WebView)
					

更多细节,见 构建采用 CMake 概述。

采用 qmake 构建

要配置采用 qmake 构建模块,添加模块作为值为 QT 变量在工程的 .pro 文件:

QT += webview
					

局限性

由于平台的限制,重叠 WebView with other QML components is not supported. Doing this will have unpredictable results, which may differ from platform to platform. Applications can also not rely on events in the WebView to propagate into the Qt event delivery system. E.g. it is not possible to "overlay" an invisible item on top of the WebView to handle certain events, or to handle events that the WebView doesn't process in a parent item.

范例

Look at the Qt WebView 范例 了解如何在应用程序中使用 API 的演示。

参考

许可

Qt WebView 在商业许可下是可用的来自 Qt 公司 。此外,它是可用的根据 GNU LGPL (次一般公共许可) 第 3 版 ,或 GNU GPL (一般公共许可) 第 2 版 。见 Qt 许可 进一步了解细节。