本页内容

WebSocketServer QML Type

QWebSocketServer 的 QML 接口。更多内容...

Import Statement: import QtWebSockets 1.12

属性

信号

详细描述

物业文件

accept : bool

当服务器处于监听状态时,将此参数设置为 true 以接受传入的客户端连接。当设置为 false 时,将拒绝传入的连接。默认情况下,接受连接。

errorString : string [read-only]

发生错误时,将错误消息转换为字符串。

host : string

服务器的主机地址。默认使用 localhost。

listen : bool

当服务器需要监听客户端连接时,将此参数设为 true;否则设为 false。当设为 true 时,服务器将在由 host 和 port 定义的指定 URL 上进行监听,且当 accept 为 true 时,将接受传入的客户端连接。否则,服务器将处于关闭状态。默认情况下,服务器不进行监听。

name : string

在 HTTP 握手阶段使用的该服务器名称。

port : int

该服务器监听的端口。该值必须在 0-65535 范围内。

默认情况下,系统会自动选择一个端口。

supportedSubprotocols : list<string> [since 6.4]

服务器支持的协议列表。

该属性自 Qt 6.4 起引入。

url : url [read-only]

客户端 WebSockets 可连接到的服务器 URL。该 URL 使用ws://方案,并包含服务器监听的端口号和服务器的主机地址。

Signal 文档

clientConnected(WebSocket webSocket)

当客户端连接到此服务器时,会触发此信号。webSocket 即为新创建的WebSocket 。

注意: 对应的处理程序 是onClientConnected 。

© 2026 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.