Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Issues with Qt Bluetooth Scanner (android)
Qt 6.11 is out! See what's new in the release blog

Issues with Qt Bluetooth Scanner (android)

Scheduled Pinned Locked Moved Solved Mobile and Embedded
8 Posts 2 Posters 1.1k Views 1 Watching
  • 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.
  • ahsan737A Offline
    ahsan737A Offline
    ahsan737
    wrote on last edited by
    #1

    Greetings,
    I have defined Bluetooth Scanner in Class A (bluetooth_server) and I want to display the scanned available devices in Class B.
    I have done it but it is working inefficiently, the problem is that scanned devices don't always show up in ListView, sometimes I need to close the app and make several try to display available devices.

    • Also, the scanner works fine if I turn off Bluetooth enter the app and then turn it on.
    J.HilkJ 1 Reply Last reply
    0
    • ahsan737A ahsan737

      Greetings,
      I have defined Bluetooth Scanner in Class A (bluetooth_server) and I want to display the scanned available devices in Class B.
      I have done it but it is working inefficiently, the problem is that scanned devices don't always show up in ListView, sometimes I need to close the app and make several try to display available devices.

      • Also, the scanner works fine if I turn off Bluetooth enter the app and then turn it on.
      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      @ahsan737
      do you continuously scan, or only one scan ?

      There's no guarantee that all devices will be found on the first scan


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      ahsan737A 1 Reply Last reply
      0
      • J.HilkJ J.Hilk

        @ahsan737
        do you continuously scan, or only one scan ?

        There's no guarantee that all devices will be found on the first scan

        ahsan737A Offline
        ahsan737A Offline
        ahsan737
        wrote on last edited by
        #3

        @j-hilk only once using signal/slot of QBluetoothDeviceDiscoveryAgent.
        here is the code.

        **Class A (bluetooth_server)**
        
            agent = new QBluetoothDeviceDiscoveryAgent;
            connect(agent, SIGNAL(deviceDiscovered(QBluetoothDeviceInfo)),
                    this, SLOT(deviceDiscovered(QBluetoothDeviceInfo)));
        
            agent->start();
        
        void bluetooth_server::deviceDiscovered(const QBluetoothDeviceInfo &device)
        {
        
            emit DevicesList(device.name(),device.address().toString());
        }
        
        **Class B (UI)**
        
        server = new bluetooth_server(this);
        
            connect(server, &bluetooth_server::DevicesList,
                    this,  &bluetooth_settings::DevicesList)
        
        void bluetooth_settings::DevicesList(const QString &name, const QString &address)
        {
                ui->listWidget->addItem(name+"::"+address);
        }
        
        J.HilkJ 1 Reply Last reply
        0
        • ahsan737A ahsan737

          @j-hilk only once using signal/slot of QBluetoothDeviceDiscoveryAgent.
          here is the code.

          **Class A (bluetooth_server)**
          
              agent = new QBluetoothDeviceDiscoveryAgent;
              connect(agent, SIGNAL(deviceDiscovered(QBluetoothDeviceInfo)),
                      this, SLOT(deviceDiscovered(QBluetoothDeviceInfo)));
          
              agent->start();
          
          void bluetooth_server::deviceDiscovered(const QBluetoothDeviceInfo &device)
          {
          
              emit DevicesList(device.name(),device.address().toString());
          }
          
          **Class B (UI)**
          
          server = new bluetooth_server(this);
          
              connect(server, &bluetooth_server::DevicesList,
                      this,  &bluetooth_settings::DevicesList)
          
          void bluetooth_settings::DevicesList(const QString &name, const QString &address)
          {
                  ui->listWidget->addItem(name+"::"+address);
          }
          
          J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by
          #4

          @ahsan737
          there you have it, you have to continue scanning after its finished

          for example:

          connect(agent, &QBluetoothDeviceDiscoveryAgent::finished, agent, &QBluetoothDeviceDiscoveryAgent::start);
          
          

          make sure you compare the uuids, so that you don't add already discovered devices


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          ahsan737A 1 Reply Last reply
          1
          • J.HilkJ J.Hilk

            @ahsan737
            there you have it, you have to continue scanning after its finished

            for example:

            connect(agent, &QBluetoothDeviceDiscoveryAgent::finished, agent, &QBluetoothDeviceDiscoveryAgent::start);
            
            

            make sure you compare the uuids, so that you don't add already discovered devices

            ahsan737A Offline
            ahsan737A Offline
            ahsan737
            wrote on last edited by
            #5

            @j-hilk oh thank you so much, I am very beginner so cannot even understand documentation sometimes. Can you please give a clue how to compare the UUIDs in order to avoid already discovered devices?

            J.HilkJ 1 Reply Last reply
            0
            • ahsan737A ahsan737

              @j-hilk oh thank you so much, I am very beginner so cannot even understand documentation sometimes. Can you please give a clue how to compare the UUIDs in order to avoid already discovered devices?

              J.HilkJ Offline
              J.HilkJ Offline
              J.Hilk
              Moderators
              wrote on last edited by
              #6

              @ahsan737
              QBluetoothDeviceInfo has an access function deviceUuid save them in a QList and before adding simply parse through the list to check if the uuid was already added


              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


              Q: What's that?
              A: It's blue light.
              Q: What does it do?
              A: It turns blue.

              ahsan737A 1 Reply Last reply
              0
              • J.HilkJ J.Hilk

                @ahsan737
                QBluetoothDeviceInfo has an access function deviceUuid save them in a QList and before adding simply parse through the list to check if the uuid was already added

                ahsan737A Offline
                ahsan737A Offline
                ahsan737
                wrote on last edited by
                #7

                @j-hilk got it, thanks. I am trying it. I still cannot understand one fact that whenever I turn off Bluetooth, enter the app and then turn on Bluetooth (using localdevice.poweron ()) then it always scans immediately.

                ahsan737A 1 Reply Last reply
                0
                • ahsan737A ahsan737

                  @j-hilk got it, thanks. I am trying it. I still cannot understand one fact that whenever I turn off Bluetooth, enter the app and then turn on Bluetooth (using localdevice.poweron ()) then it always scans immediately.

                  ahsan737A Offline
                  ahsan737A Offline
                  ahsan737
                  wrote on last edited by
                  #8

                  @ahsan737 I cannot fix it on my device (Meizu X8) but I have tested the app on other device and scanner was working fine. So there is a chance this particular device is causing the problem.

                  1 Reply Last reply
                  0

                  • Login

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