WebSocket QML Type

QWebSocket 的 QML 接口。更多

Import Statement: import QtWebSockets 1.9

属性

信号

方法

详细说明

WebSockets 是一种网络技术,可通过单个 TCP 连接提供全双工通信通道。2011 年,IETF 将 WebSocket 协议标准化为RFC 6455

属性文档

active : bool

当设置为 true 时,将通过给定的 URL 与服务器建立连接。设置为 false 时,将关闭连接。默认值为 false。


errorString : string [read-only]

包含最后发生错误的描述。如果没有错误发生,该字符串为空。


negotiatedSubprotocol : string [read-only, since 6.4]

与服务器协商的 WebSocket 子协议。

此属性在 Qt 6.4 中引入。


requestedSubprotocols : list<string> [since 6.4]

要在 WebSocket 握手中发送的 WebSocket 子协议列表。

此属性在 Qt 6.4 中引入。


status : Status [read-only]

WebSocket 的状态。

状态可以有以下值:

  • WebSocket.Connecting
  • WebSocket.Open
  • WebSocket.Closing
  • WebSocket.Closed
  • WebSocket.Error

url : url

要连接的服务器网址。该 URL 必须有两种方案之一:ws://wss://。如果未提供,则使用ws://。


信号文档

binaryMessageReceived(QString message)

message 包含接收到的字节。

注: 相应的处理程序是onBinaryMessageReceived


statusChanged(Status status)

当 WebSocket 的状态发生变化时会发出该信号。status 参数提供了当前状态。

注: 相应的处理程序是onStatusChanged

另请参阅 WebSocket::status


textMessageReceived(QString message)

message 包含收到的字节。

注: 相应的处理程序是onTextMessageReceived


方法文档

void sendBinaryMessage(ArrayBuffer message)

向服务器发送参数message


void sendTextMessage(string message)

向服务器发送message


© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.