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.


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