Nominate our 2022 Qt Champions!

Unable to connect to bluetooth device

  • Hello,

    I am using btscanner qt example to connect to other bluetooth device to transfer data.
    Currently the example contains only displaying of bluetooth device and upon selecting the device we will get all the services provided by the remote device.
    I added my code to create an rfcomm connection inside addService function of service.cpp

    Code is as follows:

    socket = new QBluetoothSocket(QBluetoothServiceInfo::RfcommProtocol);
    qDebug() << serviceInfo.serviceUuid();
    if(socket != NULL)
    qDebug() << "Create socket" << serviceInfo.device().address().toString();
    socket->connectToService(serviceInfo.device().address(), QBluetoothUuid(QBluetoothUuid::ObexObjectPush));
    qDebug() << "ConnectToService done";

       connect(socket, SIGNAL(readyRead()), this, SLOT(readSocket()));

    connect(socket, SIGNAL(connected()), this, SLOT(connected()));
    connect(socket, SIGNAL(disconnected()), this, SLOT(disconnected()));
    with this code i am getting proper selected bluetooth device name but the serviceUUid is all zeros.

    and also i get the error saying device is offline.

    later i change serviceDiscoveryAgent.start() function to serviceDiscoveryAgent.start(QBluetoothServiceDiiscoveryAgent::DiscoveryMode::FullDiscovery)

    this time i get the same result but the error is " unknown host state "

    I am running the code in qt 5.5.
    I am flashing the apk on nexus 7 tablet and samsung mobile. am getting same result.
    I am assuming that i am missing to add certain code but unable to find

    Any solutions ?
    Thank you.

  • @RohitIti Can some one provide me qt Bluetooth code which works

    1. search for deceives
    2. pair and connect to selected device using OPP protocol

Log in to reply