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