当前位置:网站首页>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 .
边栏推荐
- 学习MVVM笔记(一)
- Is there a sudden failure on the line? How to make emergency diagnosis, troubleshooting and recovery
- Threejs Internet of things, 3D visualization of farms (II)
- Open graph protocol
- Network security - record web vulnerability fixes
- Mxnet imports various libcudarts * so、 libcuda*. So not found
- Managed service network: application architecture evolution in the cloud native Era
- 网络安全-记录web漏洞修复
- 直播預告 | 容器服務 ACK 彈性預測最佳實踐
- 【虚幻引擎UE】实现测绘三脚架展开动画制作
猜你喜欢
Moco is not suitable for target detection? MsrA proposes object level comparative learning target detection pre training method SOCO! Performance SOTA! (NeurIPS 2021)...
About the project error reporting solution of mpaas Pb access mode adapting to 64 bit CPU architecture
小程序中实现文章的关注功能
取余操作是一个哈希函数
A real day for Beijing programmers!!!!!
Raki's notes on reading paper: code and named entity recognition in stackoverflow
直播預告 | 容器服務 ACK 彈性預測最佳實踐
Function (basic: parameter, return value)
Network security - record web vulnerability fixes
Is "golden nine and silver ten" the best time to find a job? Not necessarily
随机推荐
Learning notes 8
Neural network and deep learning Chapter 1: introduction reading questions
Seven join join queries of MySQL
Fonction (sujette aux erreurs)
Possible stack order of stack order with length n
解密函数计算异步任务能力之「任务的状态及生命周期管理」
Neural networks and deep learning Chapter 3: linear model reading questions
[uniapp] system hot update implementation ideas
取余操作是一个哈希函数
Looking back on 2021, looking forward to 2022 | a year between CSDN and me
Threejs Internet of things, 3D visualization of farm (III) model display, track controller setting, model moving along the route, model adding frame, custom style display label, click the model to obt
User behavior collection platform
Threejs Internet of things, 3D visualization of farms (I)
WeNet:面向工业落地的E2E语音识别工具
【科普】热设计基础知识:5G光器件之散热分析
【虚幻引擎UE】运行和启动的区别,常见问题分析
Discussion on the dimension of confrontation subspace
Ctfshow web entry code audit
[popular science] basic knowledge of thermal design: heat dissipation analysis of 5g optical devices
[phantom engine UE] package error appears! Solutions to findpin errors