QML WebSocket Client

Explains how to write a QML WebSocket client example.

The QML WebSocket Client example creates a secure and an insecure WebSocket connection to an echo server, using the QML API, and alternates between opening connections and closing them. Every time a connection has been opened, it sends a message.

QML WebSocket Client GUI

This example opens a window with a welcome message. Every time the window is clicked on, it alternates between opening and closing two connections to an external echo server. The echo server used is at ws.ifelse.io, and an Internet connection is necessary for the example to work. Also TLS must be enabled for the secure connection to work. When the connection is opened or closed, the statusChanged signal is handled by the onStatusChanged handler. Every time the socket is opened, a message is sent, and every time the socket is closed, a message is logged in the window. In addition, there is an onTextMessageReceived handler that logs to the window the messages received from the server.

Example project @ code.qt.io

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