WebSocket QML Type | Qt WebSockets | Qt 6.12.0
Description: QML interface to QWebSocket.
Keywords: qmltype

- Qt 6.12
- Qt WebSockets
- QML Types
- WebSocket
- Qt 6.12.0 Reference Documentation

# WebSocket QML Type

QML interface to QWebSocket. More...

Import Statement: | `import QtWebSockets 1.12`

- List of all members, including inherited members

## Properties

- active : bool
- errorString : string
- negotiatedSubprotocol : string `(since 6.4)`
- requestedSubprotocols : list<string> `(since 6.4)`
- status : Status
- url : url

## Signals

- binaryMessageReceived(QString message)
- pong(quint64 elapsedTime, ArrayBuffer payload) `(since 6.10)`
- statusChanged(Status status)
- textMessageReceived(QString message)

## Methods

- void ping() `(since 6.10)`
- void ping(ArrayBuffer payload) `(since 6.10)`
- void sendBinaryMessage(ArrayBuffer message)
- void sendTextMessage(string message)

## Detailed Description

WebSockets is a web technology providing full-duplex communications channels over a single TCP connection. The WebSocket protocol was standardized by the IETF as RFC 6455 in 2011.

## Property Documentation

### active : bool

When set to true, a connection is made to the server with the given url. When set to false, the connection is closed. The default value is false.

### errorString : string `[read-only]`

Contains a description of the last error that occurred. When no error occurrred, this string is empty.

### negotiatedSubprotocol : string `[read-only, since 6.4]`

The WebSocket subprotocol that has been negotiated with the server.

This property was introduced in Qt 6.4.

### requestedSubprotocols : list<string> `[since 6.4]`

The list of WebSocket subprotocols to send in the WebSocket handshake.

This property was introduced in Qt 6.4.

### status : Status `[read-only]`

Status of the WebSocket.

The status can have the following values:

- WebSocket.Connecting
- WebSocket.Open
- WebSocket.Closing
- WebSocket.Closed
- WebSocket.Error

### url : url

Server url to connect to. The url must have one of 2 schemes: ws:// or wss://. When not supplied, then ws:// is used.

## Signal Documentation

### binaryMessageReceived(QString message)

This signal is emitted when a binary message is received. message contains the bytes received.

Note: The corresponding handler is `onBinaryMessageReceived`.

### `[since 6.10]` pong(quint64 elapsedTime, ArrayBuffer payload)

Emitted when a pong message is received in reply to a previous ping. elapsedTime contains the roundtrip time in milliseconds and payload contains an optional payload that was sent with the ping.

Note: The corresponding handler is `onPong`.

This signal was introduced in Qt 6.10.

See also ping().

### statusChanged(Status status)

This signal is emitted when the status of the WebSocket changes. The status argument provides the current status.

Note: The corresponding handler is `onStatusChanged`.

See also WebSocket::status.

### textMessageReceived(QString message)

This signal is emitted when a text message is received. message contains the bytes received.

Note: The corresponding handler is `onTextMessageReceived`.

## Method Documentation

### `[since 6.10]` void ping()

### `[since 6.10]` void ping(ArrayBuffer payload)

Pings the server to indicate that the connection is still alive. An additional payload can be sent along with the ping message.

The size of the payload cannot be bigger than 125 bytes. If it is larger, the payload is clipped to 125 bytes.

Note: QWebSocket and QWebSocketServer handles ping requests internally, which means they automatically send back a pong response to the peer.

These methods were introduced in Qt 6.10.

See also pong().

### void sendBinaryMessage(ArrayBuffer message)

Sends the parameter message to the server.

### void sendTextMessage(string message)

Sends message to the server.