Qt WebChannel

Qt WebChannel 使服務器 (QML/C++ 應用程序) 和客戶端 (HTML/JavaScript 或 QML 應用程序) 之間能夠點對點通信。它支持開箱即用通過 Qt WebEngine . In addition, it can work on all browsers that support WebSockets , enabling Qt WebChannel clients to run in any JavaScript environment (including QML). This requires implementing a custom transport based on Qt WebSockets.

模塊提供 JavaScript 庫,用於無縫集成 C++ 和 QML 應用程序與 HTML/JavaScript 和 QML 客戶端。客戶端必須使用 JavaScript 庫,去訪問由主機應用程序發布的序列化 QObject。

使用模塊

QML API

The QML types of the module are available through the QtWebChannel 導入。要使用類型,添加以下 import 語句到 .qml 文件:

import QtWebChannel
					

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 WebChannel)
target_link_libraries(mytarget PRIVATE Qt6::WebChannel)
					

更多細節,見 構建采用 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 += webchannel
					

範例

參考

許可

Qt WebChannel 在商業許可下是可用的來自 Qt 公司 。此外,它在自由軟件許可下也是可用的。這些自由軟件許可是 GNU LGPL (次一般公共許可) 第 3 版 ,或 GNU GPL (一般公共許可) 第 2 版 。見 Qt 許可 進一步瞭解細節。