- Qt 6.7
- Qt WebSockets
- Qt WebSockets Examples
- QML WebSocket Client
- Qt 6.7.1 Reference Documentation

# 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.

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