Cannnot find blutetooth device
Solved
General and Desktop
-
Hello, I am trying to find a hc05-bluetooth 2.0 module with the following code, which I have from the QtDocu (https://doc.qt.io/qt-5/qtbluetooth-overview.html#scanning-for-bluetooth-devices). My problem is that my program does not find/scan my bluetooth device
MainWindow.cpp
#include "mainwindow.h" #include "ui_mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { agent = new QBluetoothDeviceDiscoveryAgent(this); ui->setupUi(this); connect(agent,SIGNAL(deviceDiscovered(QBluetoothDeviceInfo)),this, SLOT(deviceDiscovered(QBluetoothDeviceInfo))); agent->start(QBluetoothDeviceDiscoveryAgent::ClassicMethod); socket = new QBluetoothSocket(QBluetoothServiceInfo::RfcommProtocol); } MainWindow::~MainWindow() { delete ui; } void MainWindow::on_btn_find_clicked() { ui->listwdg_devices->clear(); agent->stop(); agent->start(); } void MainWindow::deviceDiscovered(const QBluetoothDeviceInfo &device) { qDebug() << "Found new device:" << device.name() << '(' << device.address().toString() << ')'; ui->listwdg_devices->addItem(device.address().toString()); } void MainWindow::on_listwdg_devices_itemClicked(QListWidgetItem *item) { string = item->text(); static const QString serviceUuid(QStringLiteral("00001101-0000-1000-8000-00805F9B34FB")); socket->connectToService(QBluetoothAddress(string), QBluetoothUuid(serviceUuid), QIODevice::ReadWrite); }
MainWindow.h
private slots: void on_btn_find_clicked(); void deviceDiscovered(const QBluetoothDeviceInfo &device); void on_listwdg_devices_itemClicked(QListWidgetItem *item); private: Ui::MainWindow *ui; QBluetoothDeviceDiscoveryAgent *agent;/ QBluetoothSocket *socket; QString string;
-
Hello, I am trying to find a hc05-bluetooth 2.0 module with the following code, which I have from the QtDocu (https://doc.qt.io/qt-5/qtbluetooth-overview.html#scanning-for-bluetooth-devices). My problem is that my program does not find/scan my bluetooth device
MainWindow.cpp
#include "mainwindow.h" #include "ui_mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { agent = new QBluetoothDeviceDiscoveryAgent(this); ui->setupUi(this); connect(agent,SIGNAL(deviceDiscovered(QBluetoothDeviceInfo)),this, SLOT(deviceDiscovered(QBluetoothDeviceInfo))); agent->start(QBluetoothDeviceDiscoveryAgent::ClassicMethod); socket = new QBluetoothSocket(QBluetoothServiceInfo::RfcommProtocol); } MainWindow::~MainWindow() { delete ui; } void MainWindow::on_btn_find_clicked() { ui->listwdg_devices->clear(); agent->stop(); agent->start(); } void MainWindow::deviceDiscovered(const QBluetoothDeviceInfo &device) { qDebug() << "Found new device:" << device.name() << '(' << device.address().toString() << ')'; ui->listwdg_devices->addItem(device.address().toString()); } void MainWindow::on_listwdg_devices_itemClicked(QListWidgetItem *item) { string = item->text(); static const QString serviceUuid(QStringLiteral("00001101-0000-1000-8000-00805F9B34FB")); socket->connectToService(QBluetoothAddress(string), QBluetoothUuid(serviceUuid), QIODevice::ReadWrite); }
MainWindow.h
private slots: void on_btn_find_clicked(); void deviceDiscovered(const QBluetoothDeviceInfo &device); void on_listwdg_devices_itemClicked(QListWidgetItem *item); private: Ui::MainWindow *ui; QBluetoothDeviceDiscoveryAgent *agent;/ QBluetoothSocket *socket; QString string;
-
@Chaki Which OS and which Qt version?
Is Bluetooth enabled on the host?
Are any other devices found?