How to use on-board raspberry-pi bluetooth with qt creator?



  • Hi there
    Problem Statement - I am using Qt Creator 3.2.1 (IDE Qt 5.3.2) and I am trying to control on-board bluetooth on raspberry pi 3 B+ using Qt creator
    I want to scan bluetooth devices and connect to them using Qt

    My work -

    I have included QT += bluetooth library in .pro file

    My code -

    #include <qbluetoothlocaldevice.h>
    #include<qbluetoothdevicediscoveryagent.h>
    #include<qbluetoothaddress.h>

    void MainWindow::startScan()
    {discoveryAgent->start();
    }

    void MainWindow::on_discoverable_clicked(bool checked)
    {
    if (checked)
    {
    localDevice>setHostMode(QBluetoothLocalDevice::HostDiscoverable);
    }
    else
    {
    localDevice>setHostMode(QBluetoothLocalDevice::HostConnectable);
    }
    }

    void MainWindow::on_power_clicked(bool checked)
    {
    if (checked)
    { localDevice->powerOn(); }
    else
    {
    localDevice>setHostMode(QBluetoothLocalDevice::HostPoweredOff);
    }
    }

    I took the help from this link -
    https://code.qt.io/cgit/qt/qtconnectivity.git/tree/examples/bluetooth/btscanner?h=5.13
    But I am not able to implement that. I am quite new in qt bluetooth

    My Requiement -
    I need the guidance how could I proceed in Qt bluetooth to control raspberry pi - on board bluetooth


Log in to reply