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. How to scanning for bluetooth devices?

How to scanning for bluetooth devices?

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 2 Posters 1.7k 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.
  • V Offline
    V Offline
    victor wang
    wrote on last edited by
    #1

    Hi All,
    I'm using qt5.5 on my computer and using Linux+QT wayland for my OS system.
    I wanna scanning for my blutooth devices and I do it with below link.
    Document

    This is what I write in my program.

    void MainWindow::on_play_clicked()
    {
    QBluetoothLocalDevice localDevice;
    QString localDeviceName;
    
    // Check if Bluetooth is available on this device
    if (localDevice.isValid()) {
    
           // Turn Bluetooth on
            localDevice.powerOn();
    
           // Read local device name
           localDeviceName = localDevice.name();
    
           // Make it visible to others
           localDevice.setHostMode(QBluetoothLocalDevice::HostDiscoverable);
    
           // Get connected devices
           QList<QBluetoothAddress> remotes;
           remotes = localDevice.connectedDevices();
     }
    else
    {
          qDebug("local Device is not available");
    }
    
    }
    

    But It always show "local Device is not available".
    Why is this happening?
    How can I solve this question?
    Thanks in Advanced!

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      I'd go with the static QBluetoothLocalDevice::allDevices function to check the list of devices and see if anything is available.

      Did you also check that you have the bluez libraries installed on your system ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      V 2 Replies Last reply
      0
      • SGaistS SGaist

        Hi,

        I'd go with the static QBluetoothLocalDevice::allDevices function to check the list of devices and see if anything is available.

        Did you also check that you have the bluez libraries installed on your system ?

        V Offline
        V Offline
        victor wang
        wrote on last edited by victor wang
        #3

        @SGaist
        Yes, I had try to connect bluetooth directly from my system last week.
        And I'm using bluez5 to do it.
        I'm sure it connect perfectly.

        But yesterday I found that something going wrong with my system.
        I can't "lsusb".
        I doubt that it is the problem which caused my device invalid in QT progrm.

        I will try again and the advise you gave then that you know the result.
        Thanks for the reply.

        1 Reply Last reply
        0
        • SGaistS SGaist

          Hi,

          I'd go with the static QBluetoothLocalDevice::allDevices function to check the list of devices and see if anything is available.

          Did you also check that you have the bluez libraries installed on your system ?

          V Offline
          V Offline
          victor wang
          wrote on last edited by
          #4

          @SGaist
          Here I'm using QBluetoothLocalDevice::allDevices() to check the available device.
          This is how I designed.

          QList<QBluetoothHostInfo> infos = QBluetoothLocalDevice::allDevices();
          if(infos.isempty)
          {
                qDebug("It is empty");
          }
          

          I can't understand why it will show empty.
          I'm sure that I can connect my phone by running commands in terminal directly.

          Why is infos empty?

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            In that case, you should try to run your application once you connected your phone.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            V 1 Reply Last reply
            0
            • SGaistS SGaist

              In that case, you should try to run your application once you connected your phone.

              V Offline
              V Offline
              victor wang
              wrote on last edited by
              #6

              @SGaist
              Is that you mean I have to connect my phone first then run my QT application?

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Yes, so you ensure that you have at least one active Bluetooth device on your computer.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                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