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 許可 進一步瞭解細節。