BluetoothSocket QML Type

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

Import Statement: import QtBluetooth 5.12
Since: Qt 5.2

Properties

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
  • RemoteHostClosedError

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 (except NoServiceSet) are derived from QBluetoothSocket::SocketState. This property is read-only. NoServiceSet indicates that the socket state is not yet available due to the service not being set yet.

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.

© The Qt Company Ltd
Licensed under the GNU Free Documentation License, Version 1.3.
https://doc.qt.io/qt-5.12/qml-qtbluetooth-bluetoothsocket.html