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。
The QML types of the module are available through the
QtWebChannel
导入。要使用类型,添加以下 import 语句到 .qml 文件:
import QtWebChannel
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 .
使用
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 概述。
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 许可 进一步了解细节。