Qt 6.2 Android Bluetooth Socket connect Error
-
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.
-
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
-
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.2I 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.
-
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
-
same problem with Qt 6.2.1
resolved in 6.2.3: https://bugreports.qt.io/browse/QTBUG-98353