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() 先于创建 QGuiApplication instance and before window's QPlatformOpenGLContext 被创建。

Using The Module

QML API

The QML types of the module are available through the QtWebView 导入。要使用类型,添加以下 import 语句到 .qml 文件:

import QtWebView
					

C++ API

Using a Qt module's C++ API requires linking against the module library, either directly or through other dependencies. Several build tools have dedicated support for this, including CMake and qmake .

构建采用 CMake

使用 find_package() command to locate the needed module component in the Qt6 包:

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

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

采用 qmake 构建

To configure the module for building with qmake, add the module as a value of the QT variable in the project's .pro file:

QT += webview
					

局限性

由于平台的限制,重叠 WebView with other QML components is not supported. Doing this will have unpredictable results, which may differ from platform to platform.

范例

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

参考

许可

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