当前位置:网站首页>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 .
边栏推荐
- MySQL: view with subquery in the from clause limit
- 函数(基本:参数,返回值)
- PHP reads the INI file and writes the modified content
- Ffmepg usage guide
- [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)
- 取余操作是一个哈希函数
- A應用喚醒B應該快速方法
- SPI read / write flash principle + complete code
- 函數(易錯)
- WeNet:面向工业落地的E2E语音识别工具
猜你喜欢
Moco is not suitable for target detection? MsrA proposes object level comparative learning target detection pre training method SOCO! Performance SOTA! (NeurIPS 2021)...
Common features of ES6
Discussion on the dimension of confrontation subspace
指针函数(基础)
[moteur illusoire UE] il ne faut que six étapes pour réaliser le déploiement du flux de pixels ue5 et éviter les détours! (4.26 et 4.27 principes similaires)
TPG x AIDU|AI领军人才招募计划进行中!
3 minutes learn to create Google account and email detailed tutorial!
[popular science] basic knowledge of thermal design: heat dissipation analysis of 5g optical devices
Managed service network: application architecture evolution in the cloud native Era
Scheduling system of kubernetes cluster
随机推荐
自动语音识别(ASR)研究综述
User behavior collection platform
Looking back on 2021, looking forward to 2022 | a year between CSDN and me
程序员应该怎么学数学
Seven join join queries of MySQL
【FineBI】使用FineBI制作自定义地图过程
【虚幻引擎UE】实现测绘三脚架展开动画制作
web资源部署后navigator获取不到mediaDevices实例的解决方案(navigator.mediaDevices为undefined)
PR video clip (project packaging)
[Chongqing Guangdong education] 2408t Chinese contemporary literature reference test in autumn 2018 of the National Open University
快手、抖音、视频号交战内容付费
PHP读取ini文件并修改内容写入
Rk3399 platform development series explanation (network debugging) 7.29 summary of network performance tools
Official announcement! The third cloud native programming challenge is officially launched!
【虚幻引擎UE】打包报错出现!FindPin错误的解决办法
Discussion on the dimension of confrontation subspace
How to realize real-time audio and video chat function
函数(易错)
【虛幻引擎UE】實現UE5像素流部署僅需六步操作少走彎路!(4.26和4.27原理類似)
美国5G Open RAN再遭重大挫败,抗衡中国5G技术的图谋已告失败