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. Find bluetooth device
Qt 6.11 is out! See what's new in the release blog

Find bluetooth device

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 2 Posters 607 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.
  • M Offline
    M Offline
    Mihaill
    wrote on last edited by
    #1

    Hi!
    I use Windows 10, Qt 6.2.
    I wont find bluetooth device, but cand do this. Programm not see devices.

    #ifndef APPCORE_H
    #define APPCORE_H
    
    #include <QObject>
    #include <QDebug>
    #include <QJSEngine>
    #include <QQmlEngine>
    #include <QJsonDocument>
    #include <QJsonObject>
    #include <QJsonArray>
    #include <QJsonValue>
    #include <QBluetoothLocalDevice>
    #include <QBluetoothDeviceDiscoveryAgent>
    #include <QBluetoothDeviceInfo>
    #include <QBluetoothSocket>
    
    class AppCore: public QObject
    {
        Q_OBJECT
    public:
        AppCore();
        ~AppCore();
    
    public slots:
        void startAppCore();
        void getAvailableBluetooth();
    
    private:
        QBluetoothDeviceDiscoveryAgent * m_bluetoothAgent = new QBluetoothDeviceDiscoveryAgent;
        QBluetoothSocket *m_bluetoothSocket = new QBluetoothSocket(QBluetoothServiceInfo::RfcommProtocol);
    
    private slots:
        void onBluetoothDeviceDiscovered(const QBluetoothDeviceInfo &info);
    };
    
    static QObject *singeltonProvider(QQmlEngine *engine, QJSEngine *scriptEngine)
    {
        Q_UNUSED(engine);
        Q_UNUSED(scriptEngine);
    
        AppCore *appCore=new AppCore();
        return appCore;
    }
    
    #endif // APPCORE_H
    
    #include "appcore.h"
    
    AppCore::AppCore()
    {
        connect(m_bluetoothAgent, &QBluetoothDeviceDiscoveryAgent::deviceDiscovered, this, &AppCore::onBluetoothDeviceDiscovered);
        m_bluetoothAgent->start();
    }
    
    AppCore::~AppCore()
    {
    
    }
    
    void AppCore::startAppCore()
    {
    
    }
    
    void AppCore::getAvailableBluetooth()
    {
    
    }
    
    void AppCore::onBluetoothDeviceDiscovered(const QBluetoothDeviceInfo &info)
    {
        qDebug()<<"11111111111111111111111";
        qDebug()<<info.name()<<info.address();
    }
    
    JonBJ 1 Reply Last reply
    0
    • M Mihaill

      Hi!
      I use Windows 10, Qt 6.2.
      I wont find bluetooth device, but cand do this. Programm not see devices.

      #ifndef APPCORE_H
      #define APPCORE_H
      
      #include <QObject>
      #include <QDebug>
      #include <QJSEngine>
      #include <QQmlEngine>
      #include <QJsonDocument>
      #include <QJsonObject>
      #include <QJsonArray>
      #include <QJsonValue>
      #include <QBluetoothLocalDevice>
      #include <QBluetoothDeviceDiscoveryAgent>
      #include <QBluetoothDeviceInfo>
      #include <QBluetoothSocket>
      
      class AppCore: public QObject
      {
          Q_OBJECT
      public:
          AppCore();
          ~AppCore();
      
      public slots:
          void startAppCore();
          void getAvailableBluetooth();
      
      private:
          QBluetoothDeviceDiscoveryAgent * m_bluetoothAgent = new QBluetoothDeviceDiscoveryAgent;
          QBluetoothSocket *m_bluetoothSocket = new QBluetoothSocket(QBluetoothServiceInfo::RfcommProtocol);
      
      private slots:
          void onBluetoothDeviceDiscovered(const QBluetoothDeviceInfo &info);
      };
      
      static QObject *singeltonProvider(QQmlEngine *engine, QJSEngine *scriptEngine)
      {
          Q_UNUSED(engine);
          Q_UNUSED(scriptEngine);
      
          AppCore *appCore=new AppCore();
          return appCore;
      }
      
      #endif // APPCORE_H
      
      #include "appcore.h"
      
      AppCore::AppCore()
      {
          connect(m_bluetoothAgent, &QBluetoothDeviceDiscoveryAgent::deviceDiscovered, this, &AppCore::onBluetoothDeviceDiscovered);
          m_bluetoothAgent->start();
      }
      
      AppCore::~AppCore()
      {
      
      }
      
      void AppCore::startAppCore()
      {
      
      }
      
      void AppCore::getAvailableBluetooth()
      {
      
      }
      
      void AppCore::onBluetoothDeviceDiscovered(const QBluetoothDeviceInfo &info)
      {
          qDebug()<<"11111111111111111111111";
          qDebug()<<info.name()<<info.address();
      }
      
      JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by JonB
      #2

      @Mihaill

      • Your code as shown has no call to free function singeltonProvider(). Does it even get called?

      • You might check QBluetoothDeviceDiscoveryAgent::DiscoveryMethods QBluetoothDeviceDiscoveryAgent::supportedDiscoveryMethods() to make sure that it can do any BT discovery at all.

      • You say you are Windows but do not mention compiler? From Changes to Qt Bluetooth:

      Win32 backend has been removed. There will not be a working Bluetooth backend when Qt is built with mingw.

      ?

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Mihaill
        wrote on last edited by
        #3

        @JonB said in Find bluetooth device:
        I use singeltonProvider() in main.cpp
        I use MinGw 64 bit qt 6.2.3
        QBluetoothDeviceDiscoveryAgent::supportedDiscoveryMethods() return

        QFlags<QBluetoothDeviceDiscoveryAgent::DiscoveryMethod>(NoMethod)
        

        And programm said

        qt.bluetooth: Dummy backend running. Qt Bluetooth module is non-functional.
        
        JonBJ 1 Reply Last reply
        0
        • M Mihaill

          @JonB said in Find bluetooth device:
          I use singeltonProvider() in main.cpp
          I use MinGw 64 bit qt 6.2.3
          QBluetoothDeviceDiscoveryAgent::supportedDiscoveryMethods() return

          QFlags<QBluetoothDeviceDiscoveryAgent::DiscoveryMethod>(NoMethod)
          

          And programm said

          qt.bluetooth: Dummy backend running. Qt Bluetooth module is non-functional.
          
          JonBJ Online
          JonBJ Online
          JonB
          wrote on last edited by
          #4

          @Mihaill
          Exactly! That is why it is worth checking these things. So since your are mingw you have your answer --- it is non-functional.

          1 Reply Last reply
          0
          • M Offline
            M Offline
            Mihaill
            wrote on last edited by
            #5

            But how used BT on windows?

            JonBJ 1 Reply Last reply
            0
            • M Mihaill

              But how used BT on windows?

              JonBJ Online
              JonBJ Online
              JonB
              wrote on last edited by
              #6

              @Mihaill ...By using the MSVC compiler... ?

              1 Reply Last reply
              2
              • M Offline
                M Offline
                Mihaill
                wrote on last edited by
                #7

                thank, it's work

                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