Qt WebSockets

WebSocket is a web-based protocol designed to enable a two-way interactive communication session between a client application and a remote host. It enables the two entities to send data back and forth if the initial handshake succeeds.

Qt WebSockets 模块提供 C++ 和 QML 接口,使 Qt 应用程序能够充当可以处理 WebSocket 请求的服务器、可以从服务器接收消费数据的客户端、或两者。

使用模块

QML API

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

import QtWebSockets
					

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

更多细节,见 构建采用 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 += websockets
					

范例

参考

一致性

许可

Qt WebSockets 在商业许可下是可用的来自 Qt 公司 。此外,它在自由软件许可下也是可用的。从 Qt 5.4 起,这些自由软件许可是 GNU LGPL (次一般公共许可) 第 3 版 ,或 GNU GPL (一般公共许可) 第 2 版 。见 Qt 许可 进一步了解细节。