QML WebSocket 客户端
说明如何编写 QML WebSocket 客户端示例。
QML WebSocket Client 示例使用 QML API 创建了一个与 echo 服务器的安全和不安全WebSocket连接,并交替打开和关闭连接。每打开一个连接,它就发送一条信息。
本示例打开了一个窗口,其中包含一条欢迎信息。每次点击该窗口,它都会交替打开和关闭与外部回声服务器的两个连接。所使用的回声服务器位于 ws.ifelse.io,要使示例正常运行,必须有互联网连接。此外,必须启用 TLS 才能实现安全连接。打开或关闭连接时,onStatusChanged 处理程序会处理状态改变信号。每次打开套接字都会发送一条信息,每次关闭套接字都会在窗口中记录一条信息。此外,还有一个 onTextMessageReceived 处理程序,用于在窗口中记录从服务器收到的消息。
© 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.