Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Cannnot find blutetooth device
Qt 6.11 is out! See what's new in the release blog

Cannnot find blutetooth device

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 407 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Chaki
    wrote on last edited by Chaki
    #1

    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;
    
    jsulmJ 1 Reply Last reply
    0
    • C Chaki

      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;
      
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Chaki Which OS and which Qt version?
      Is Bluetooth enabled on the host?
      Are any other devices found?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      C 1 Reply Last reply
      0
      • jsulmJ jsulm

        @Chaki Which OS and which Qt version?
        Is Bluetooth enabled on the host?
        Are any other devices found?

        C Offline
        C Offline
        Chaki
        wrote on last edited by Chaki
        #3

        @jsulm I have Windows 10 and qt version 5.15.0
        I have enabled bluetooth via the Windows settings and I am not able to find any other devices

        1 Reply Last reply
        0
        • C Offline
          C Offline
          Chaki
          wrote on last edited by
          #4

          Edit: I solved the problem with changing:
          agent->start(QBluetoothDeviceDiscoveryAgent::ClassicMethod);
          to
          agent->start();

          1 Reply Last reply
          3

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved