This blog post is a one of the series of Bluetooth operations in qml. This post talks about how Bluetooth devices can be scanned in qml using the classes provided by Qt.
Bluetooth is a short-range (less than 100 meters) wireless technology. It has a reasonably high data transfer rate of 2.1 Mb/s, which makes it ideal for transferring data between devices. Bluetooth connectivity is based on basic device management, such as scanning for devices, gathering information about them, and exchanging data between them.
Bluetooth API in Qt:
The Bluetooth API provides connectivity between Bluetooth enabled devices. This is typically used for scanning the device ,pairing with device , transferring the data between the devices.
In this post we will have a look on how to scan and discover the devices using Bluetooth API in qml.
QML uses a model, BluetoothDiscoveryModel which has the details of all scanned devices. This provides a model of connectable devices. This model is filled based on the enumeration set to discoverymode property. Here as we are interested to scan devices we use BluetoothDiscoveryModel.DeviceDiscovery.
This model has following roles:
- name – The devices name and address
- deviceName – The name of the device
- remoteAddress – The address of the discovered device.
Using these three roles we can get the name and address of the device. The below example code scans for devices and displays the list of devices with name and its address.
import QtQuick 2.0
import QtBluetooth 5.0 // Requires to use the class of the bluetooth module
//Listview to hold the discovered device name and address
text: “Name : ” + qsTr(deviceName)
text: “Address : ” + qsTr(remoteAddress)
y:btdeviceName.height + 10
Screen shot of the above example:
For any technical support or queries feel free to write to us at firstname.lastname@example.org