Bluetooth on Android

  • Hi, I have a problem with a bluetooth device and Android.
    This is my code and after there is the log.
    The problem is that I can connect to my external Rfcomm device. I see a blue led on to indicate an active bluetooth connection.
    The problem is that, afet 2 / 4 seconds the connection will be closed.
    Have you got any idea?

    void MainWindow::connected() {
        qDebug() << "connected()";
    void MainWindow::disconnected() {
        qDebug() << "disconnected()";
    void MainWindow::error(QBluetoothServiceDiscoveryAgent::Error error) {
        qDebug() << "finished()";
    void MainWindow::finished() {
        qDebug() << "finished()";
    void MainWindow::readyRead() {
        while (socket->canReadLine()) {
            qDebug() << socket->readLine().trimmed();
    // Discovered service on "qID-17430018" "00:12:F3:30:8A:B8"
    void MainWindow::serviceDiscovered(const QBluetoothServiceInfo &info) {
        qDebug() << "Discovered service on" << info.device().name() << info.device().address().toString();
        qDebug() << "\tService name:" << info.serviceName();
        qDebug() << "\tDescription:" << info.attribute(QBluetoothServiceInfo::ServiceDescription).toString();
        qDebug() << "\tProvider:" << info.attribute(QBluetoothServiceInfo::ServiceProvider).toString();
        qDebug() << "\tL2CAP protocol service multiplexer:" << info.protocolServiceMultiplexer();
        qDebug() << "\tRFCOMM server channel:" << info.serverChannel();
        if (info.device().address().toString().compare("00:12:F3:30:8A:B8")== 0) {
            qDebug() << "connectToService()";
            socket= new QBluetoothSocket(QBluetoothServiceInfo::RfcommProtocol);
            connect(socket, SIGNAL(connected()), this, SLOT(connected()));
            connect(socket, SIGNAL(disconnected()), this, SLOT(disconnected()));
            connect(socket, SIGNAL(readyRead()), this, SLOT(readyRead()));
    D BluetoothAdapter: startDiscovery
    D BluetoothAdapter: startDiscovery = true
    D (null):0 ((null)): Discovered service on "qID-17430018" "00:12:F3:30:8A:B8"
    D (null):0 ((null)): 	Service name: "Serial Port Profile"
    D (null):0 ((null)): 	Description: ""
    D (null):0 ((null)): 	Provider: ""
    D (null):0 ((null)): 	L2CAP protocol service multiplexer: 0
    D (null):0 ((null)): 	RFCOMM server channel: 0
    D (null):0 ((null)): connectToService()
    D (null):0 ((null)): finished()
    D BluetoothUtils: isSocketAllowedBySecurityPolicy start : device null
    D BluetoothSocket: connect(): myUserId = 0
    W BluetoothAdapter: getBluetoothService() called with no BluetoothManagerCallback
    D BluetoothSocket: getInputStream(): myUserId = 0
    D BluetoothSocket: getOutputStream(): myUserId = 0
    D (null):0 ((null)): connected()
    W System.err: bt socket closed, read return: -1
    W System.err: 	at
    W System.err: 	at
    W System.err: 	at
    W System.err: 	at
    D (null):0 ((null)): disconnected()

  • Moderators

    to what kind of device are you connecting to?
    My first guess is that the remote device requires pairing before data exchange?

  • It is a rfid bluetooth reader.
    Using the original app the reader works, so it isn't a pairing problem.
    On Linux I can connect to it using rfcomm tool but not using Qt bluetooth stack.
    On Linux I obtain this error:

    //your code here
    ```Discovered service on "qID-17430018" "00:12:F3:30:8A:B8"
            Service name: "SPP"
            Description: ""
            Provider: ""
            L2CAP protocol service multiplexer: 0
            RFCOMM server channel: 1
    Discovered service on "qID-17430018" "00:12:F3:30:8A:B8"
            Service name: "SPP"
            Description: ""
            Provider: ""
            L2CAP protocol service multiplexer: 0
            RFCOMM server channel: 5
    Discovered service on "qID-17430018" "00:12:F3:30:8A:B8"
            Service name: ""
            Description: ""
            Provider: ""
            L2CAP protocol service multiplexer: -1
            RFCOMM server channel: -1
    qt.bluetooth.bluez: void QBluetoothSocketPrivate::_q_readNotify() 12 error: -1 "Risorsa temporaneamente non disponibile"

  • After much time spent on searching of what it is wrong I have implement bluetooth dev (Linux) directly.
    In 50 lines of code now I have my bluetooth device working. The connection is very quicly.
    I will write a java class to have the same on Android.
    So how to use the Qt bluetooth framework it is not clear for me.

  • Lifetime Qt Champion

    hi @mrdebug,

    your log seems to indicate a bug. can you create a report at ? (and provide a link here)


  • Probably you are right but the problem is how to try.
    I think that the Qt bluetooth core developers should have a device like my device to understand where the problem is.

  • Lifetime Qt Champion

    @mrdebug well you can at least give them as much indication as possible. If no one reports, the situation stays unchanged.

    But as you are 'Mr. Debug', you could even try to debug it ;)


Log in to reply