BluetoothSocket QML Type | Qt Bluetooth 5.6

Qt 5.6 | Qt Bluetooth | QML Types | BluetoothSocket QML Type

Qt 5.6.2 Reference Documentation

# BluetoothSocket QML Type

Enables connecting and communicating with a Bluetooth service or device. More...

Import Statement: | import QtBluetooth 5.2
Since: | Qt 5.2

- List of all members, including inherited members

## Properties

- connected : bool
- error : enumeration
- service : BluetoothService
- state : enumeration
- stringData : string

## Detailed Description

It allows a QML class connect to another Bluetooth device and exchange strings with it. Data is sent and received using a QDataStream object allowing type safe transfers of QStrings. QDataStream is a well known format and can be decoded by non-Qt applications. Note that for the ease of use, BluetoothSocket is only well suited for use with strings. If you want to use a binary protocol for your application's communication you should consider using its C++ counterpart QBluetoothSocket.

Connections to remote devices can be over RFCOMM or L2CAP. Either the remote port or service UUID is required. This is specified by creating a BluetoothService, or passing in the service return from BluetoothDiscoveryModel.

See also QBluetoothSocket and QDataStream.

## Property Documentation

connected : bool

This property holds the connection state of the socket. If the socket is connected to peer, it returns true. It can be set true or false to control the connection. When set to true, the property will not return true until the connection is established.

error : enumeration

This property holds the last error that happened.

- `NoError`
- `UnknownSocketError`
- `HostNotFoundError`
- `ServiceNotFoundError`
- `NetworkError`
- `UnsupportedProtocolError`

The errors are derived from QBluetoothSocket::SocketError. This property is read-only.

service : BluetoothService

This property holds the details of the remote service to connect to. It can be set to a static BluetoothService with a fixed description, or a service returned by service discovery.

state : enumeration

This property holds the current state of the socket.

- `NoServiceSet`
- `Unconnected`
- `ServiceLookup`
- `Connecting`
- `Connected`
- `Closing`
- `Listening`
- `Bound`

The states are derived from QBluetoothSocket::SocketState. This property is read-only.

stringData : string

This property receives or sends data to a remote Bluetooth device. Arrival of data can be detected by connecting to this properties changed signal and can be read via stringData. Setting stringData will transmit the string. If excessive amounts of data are sent, the function may block sending. Reading will never block.