Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Qt 6
  4. Qt 6.2 Android Bluetooth Socket connect Error
Forum Update on Monday, May 27th 2025

Qt 6.2 Android Bluetooth Socket connect Error

Scheduled Pinned Locked Moved Solved Qt 6
7 Posts 3 Posters 1.4k 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
    melaz123
    wrote on 3 Nov 2021, 05:26 last edited by melaz123 11 Mar 2021, 05:46
    #1

    Hi I have a simple bluetooth app running on Android 9 that borrowed from a previous example with

    void BluetoothClient::startClient(const QBluetoothServiceInfo &remoteService)
    {
        if (socket)
            return;
    
        // Connect to service
        socket = new QBluetoothSocket(QBluetoothServiceInfo::RfcommProtocol);
        qDebug() << "Create socket";
        socket->connectToService(remoteService);
        qDebug() << "ConnectToService done";
    
        connect(socket, &QBluetoothSocket::readyRead,   this, &BluetoothClient::readSocket);
        connect(socket, &QBluetoothSocket::connected,   this, QOverload<>::of(&BluetoothClient::connected));
        connect(socket, &QBluetoothSocket::disconnected,this, &BluetoothClient::stopClient);
        connect(socket,&QBluetoothSocket::errorOccurred,this, &BluetoothClient::onSocketErrorOccurred);
        connect(this, &BluetoothClient::messageReceived,this, &BluetoothClient::onMessageRecieved );
    }
    

    However, every time I run I end up with the following errors and no connection to the Bluetooth module.

    W System.err: java.lang.NoSuchMethodError: no non-static method "Landroid/bluetooth/BluetoothAdapter;.getRemoteDevice(Ljava/lang/String;)Landroid.bluetooth.BluetoothDevice;"
    W System.err: 	at org.qtproject.qt.android.QtNative.startQtApplication(Native Method)
    W System.err: 	at org.qtproject.qt.android.QtNative$7.run(QtNative.java:633)
    W System.err: 	at org.qtproject.qt.android.QtThread$1.run(QtThread.java:61)
    W System.err: 	at java.lang.Thread.run(Thread.java:764)
    

    I have tried adding the following with no luck :

    #include <QJniObject>
    #include <QJniEnvironment>
    #include <QCoreApplication>
    
    #ifdef Q_OS_ANDROID
    #include <QtCore/private/qandroidextras_p.h>
    #endif
    

    Any help is greatly appreciated.

    1 Reply Last reply
    2
    • G Offline
      G Offline
      gregorykon
      wrote on 6 Nov 2021, 12:52 last edited by
      #2

      Hi, I am new to Qt, but also have the same problem in connectToService (remote device is found but during connection I get the same exception). Just writing here in order not to double post. I thought maybe some build config might be wrong but no idea.

      Any feedback would be helpful.


      Windows 10 Home 10.0.19042
      Openjdk, jdk-11.0.12.7-hotspot, javac 11.0.12, in Gradle JavaVersion.VERSION_11 (Hope this marginally complies with the documentation Note: 'JDK 11 or earlier must be used when using Qt for Android')
      Android SDK Version 5.0, NDK Version 21.4.7075529, but project uses "21.3.6528147"

      Project Settings for Testing:
      Android_Qt_6_2_0_Clang_armeabi_v7a-Debug
      Android Build SDK: android-30
      Gradle 7.0.2
      build-tools:30.0.3
      qtMinSdkVersion=23
      qtTargetSdkVersion=30


      1 Reply Last reply
      1
      • M Offline
        M Offline
        melaz123
        wrote on 7 Nov 2021, 18:41 last edited by
        #3

        Recently tried setting the missing COARSE LOCATION permissions by editing and creating a custom android manifest with the correct target api,

        <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
        

        Both still with no luck.

        The only way I seem to be able to get it to work is to switch build to:
        Qt 5.15.2

        I get some qml errors that cause designer to not be able to display my UI but when I connect to the service I no longer get the error and I can communicate properly. Seems like a Qt 6 issue for sure.

        1 Reply Last reply
        1
        • G Offline
          G Offline
          gregorykon
          wrote on 14 Nov 2021, 22:24 last edited by
          #4

          Thanks for the info, I also tried an older version (e.g. Qt 5.14.2) and communication seems to be working fine, but yes the problem remains for Qt 6.2.0

          1 Reply Last reply
          0
          • R Offline
            R Offline
            russkij
            wrote on 25 Nov 2021, 15:08 last edited by russkij
            #5

            same problem with Qt 6.2.1

            resolved in 6.2.3: https://bugreports.qt.io/browse/QTBUG-98353

            M 1 Reply Last reply 30 Dec 2021, 21:37
            1
            • R russkij
              25 Nov 2021, 15:08

              same problem with Qt 6.2.1

              resolved in 6.2.3: https://bugreports.qt.io/browse/QTBUG-98353

              M Offline
              M Offline
              melaz123
              wrote on 30 Dec 2021, 21:37 last edited by
              #6

              @russkij Thank you for the reply and pointing out a fix, from the debugging output and the bug ticket as you mentioned this should be the fix. I will double check with my Android versions and marked as solved!

              1 Reply Last reply
              0
              • M Offline
                M Offline
                melaz123
                wrote on 21 Feb 2022, 17:46 last edited by
                #7

                With the recent release of Qt 6.2.3 I verified that this has been fixed and android bluetooth is indeed working. Thanks everyone!

                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