QML WebSocket 客户端
说明如何编写一个 QML WebSocket 客户端示例。
该 QML WebSocket 客户端示例利用 QML API 向回显服务器建立安全连接和非安全连接,并交替地打开和关闭连接。每次建立连接后,都会发送一条消息。

本示例会打开一个显示欢迎信息的窗口。每次点击该窗口时,它会交替地与外部回显服务器建立或关闭两条连接。所使用的回显服务器位于 ws.ifelse.io,且示例运行需具备互联网连接。此外,为确保安全连接正常工作,必须启用 TLS。 当连接打开或关闭时,`statusChanged` 信号由 `onStatusChanged` 处理程序处理。每次打开套接字时,都会发送一条消息;每次关闭套接字时,都会在窗口中记录一条消息。此外,还有一个 `onTextMessageReceived` 处理程序,用于将从服务器接收到的消息记录到窗口中。
© 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.