当前位置:网站首页>QT Bluetooth: a class for searching Bluetooth devices -- qbluetooth devicediscoveryagent
QT Bluetooth: a class for searching Bluetooth devices -- qbluetooth devicediscoveryagent
2022-07-05 04:28:00 【Friendly, friend】
One 、 describe
This class is used to find nearby Bluetooth devices .
Process of finding nearby Bluetooth devices :
- establish QBluetoothDeviceDiscoveryAgent Example ,
- Connect to deviceDiscovered() or finished() The signal ,
- And call start().
#include "widget.h"
#include "ui_widget.h"
#include <QBluetoothDeviceDiscoveryAgent>
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
discoveryAgent = new QBluetoothDeviceDiscoveryAgent(this);
connect(discoveryAgent, &QBluetoothDeviceDiscoveryAgent::deviceDiscovered,this, &Widget::deviceDiscovered);
}
Widget::~Widget()
{
delete ui;
}
void Widget::deviceDiscovered(const QBluetoothDeviceInfo &device)
{
qDebug() << " Discover new equipment :" << device.name() << '(' << device.address().toString() << ')';
}
void Widget::on_pushButton_clicked()
{
qDebug() << " Begin your search ";
discoveryAgent->start();
}
Two 、 Type members
1、enum QBluetoothDeviceDiscoveryAgent::DiscoveryMethod: This enumeration describes the method used by this class to search for Bluetooth devices . Not necessarily useful , See each operating system for details .
- NoMethod: Can't search . No available methods are supported .
- ClassicMethod: Search Bluetooth classic (BaseRate) equipment .
- LowEnergyMethod: Search for low-power Bluetooth devices .
2、enum QBluetoothDeviceDiscoveryAgent::Error: Possible error conditions during Bluetooth device search .
- NoError: There was no mistake .
- PoweredOffError: Bluetooth adapter is turned off , Open it before searching .
- InputOutputError: Error caused by writing or reading from device .
- InvalidBluetoothAdapterError: The local adapter address passed does not match the physical adapter address of any local Bluetooth device .
- UnsupportedPlatformError: Device search is not supported on the current platform . The error is a response to start() Set by calling .
- UnsupportedDiscoveryMethod: The current platform does not support the set search method DiscoveryMethod.
- LocationServiceTurnedOffError: Location service is turned off . When turning off location services , Unable to use Bluetooth API.
- UnknownError: An unknown error occurred .
3、 ... and 、 Member functions
1、QBluetoothDeviceDiscoveryAgent(const QBluetoothAddress &deviceAdapter, QObject *parent = nullptr)
Construct a new Bluetooth device search agent with a parent .
It USES deviceAdapter Perform device search . If deviceAdapter Is constructed by default , Then it generates QBluetoothDeviceDiscoveryAgent Object will use the local default Bluetooth adapter .
If specified deviceAdapter Not a local adapter , be error() Set to InvalidBluetoothAdapterError. Therefore, it is recommended to test the error flag immediately after using this constructor .
2、【 The signal 】void canceled()
When by calling stop() This signal will be sent when the device search is aborted .
3、【 The signal 】void deviceDiscovered(const QBluetoothDeviceInfo &info)
If I found info This signal is sent when the Bluetooth device described .
Once the collected device information , Will send a signal . however , As long as it hasn't been sent finished() The signal , Even for devices that have been discovered , Information gathering will also continue .
4、【 The signal 】void deviceUpdated(const QBluetoothDeviceInfo &info, QBluetoothDeviceInfo::Fields updatedFields)
When received by info When describing the additional information of the Bluetooth device , It will send this signal .updatedFields Signs tell which information has been updated .
During search , Some information can change dynamically , Such as signal strength and manufacturer data . This signal informs the user , If the application is displaying this data , You can update it , Instead of waiting until the discovery is complete .
5、【 The signal 】void errorOccurred(QBluetoothDeviceDiscoveryAgent::Error error)
This signal is sent when an error occurs during Bluetooth device search .error The parameter describes the error that occurred .
6、【 The signal 】void finished()
Send this signal when the Bluetooth device search is completed . If the device search ends with an error , Will not send a signal .
7、void start(QBluetoothDeviceDiscoveryAgent::DiscoveryMethods methods)
Start Bluetooth device search ( If not already started ). The search method limits the scope of device search .
Be careful :methods Only determine the type of discovery , It doesn't mean filtering results . for example , Although the method is only set to LowEnergyMethod, But the search may still include classic Bluetooth devices . This may happen because previously cached search results may be merged into search results .
void start()
Start Bluetooth device discovery ( If not already started ).
8、void stop()
Stop Bluetooth device search . Once the device search is cancelled , It will send out cancel() The signal .
9、QList<QBluetoothDeviceInfo> discoveredDevices()
Return to the list of all Bluetooth devices found .
10、QBluetoothDeviceDiscoveryAgent::Error error()
Return the last error .
11、QString errorString()
Return the readable description of the last error .
12、bool isActive()
Are you searching for Bluetooth devices .
13、int lowEnergyDiscoveryTimeout()
Returns the timeout applied to low-power Bluetooth device search ( millisecond ).
The value is -1 Indicates that the platform does not support this attribute , And the timeout of device search cannot be adjusted .
The value is 0 Indicates that you must pass stop() Endless search stopped manually .
14、void setLowEnergyDiscoveryTimeout(int timeout)
Set the maximum search time for searching low-power Bluetooth devices ( In Milliseconds ). If the timeout is 0, Then the search will always run , Until the call stop().
After restarting device search , The new timeout value will take effect . In addition, timeout does not affect classic Bluetooth device search .
For reliable low-power Bluetooth search , Use at least 40000 millisecond .
15、【static】QBluetoothDeviceDiscoveryAgent::DiscoveryMethods supportedDiscoveryMethods()
Return to the search methods supported by the current platform .
边栏推荐
- 【虚幻引擎UE】运行和启动的区别,常见问题分析
- Here comes the Lantern Festival red envelope!
- Threejs Internet of things, 3D visualization of farms (II)
- What are the building energy-saving software
- MySQL: view with subquery in the from clause limit
- 指针函数(基础)
- [uniapp] system hot update implementation ideas
- Study notes 7
- Components in protective circuit
- TPG x AIDU | AI leading talent recruitment plan in progress!
猜你喜欢

C26451: arithmetic overflow: use the operator * on a 4-byte value, and then convert the result to an 8-byte value. To avoid overflow, cast the value to wide type before calling the operator * (io.2)

level18

Invalid bound statement (not found) in idea -- problem solving

Managed service network: application architecture evolution in the cloud native Era

Live broadcast preview | container service ack elasticity prediction best practice

【虛幻引擎UE】實現UE5像素流部署僅需六步操作少走彎路!(4.26和4.27原理類似)

Raki's notes on reading paper: code and named entity recognition in stackoverflow

Scheduling system of kubernetes cluster

程序员应该怎么学数学

Observable time series data downsampling practice in Prometheus
随机推荐
Behavior perception system
Threejs realizes the drawing of the earth, geographical location annotation, longitude and latitude conversion of world coordinates threejs coordinates
Fuel consumption calculator
美国5G Open RAN再遭重大挫败,抗衡中国5G技术的图谋已告失败
A solution to the problem that variables cannot change dynamically when debugging in keil5
A應用喚醒B應該快速方法
MacBook安装postgreSQL+postgis
Judge whether the stack order is reasonable according to the stack order
How to get the first few pieces of data of each group gracefully
Here comes the Lantern Festival red envelope!
直播預告 | 容器服務 ACK 彈性預測最佳實踐
Threejs factory model 3DMAX model obj+mtl format, source file download
PHP读取ini文件并修改内容写入
[phantom engine UE] only six steps are needed to realize the deployment of ue5 pixel stream and avoid detours! (the principles of 4.26 and 4.27 are similar)
What are the building energy-saving software
快手、抖音、视频号交战内容付费
Leetcode hot topic Hot 100 day 33: "subset"
Components in protective circuit
SPI read / write flash principle + complete code
Threejs implements labels and displays labels with custom styles


