Qt Bluetooth communication



  • Hey,
    I have an application based on Qt and QML, which is on the minicomputer (UpBoard). I need to add the ability to transfer data via Bluetooth to a mobile android application. The problem is that UpBoard does not have a built-in BT. And here the questions arise:

    • which BT module to choose? USB adapter or some HC-05 / HC-06? What are the differences between them?
    • how to detect the module "programmatically" in c ++ (Qt) and start sending data? Any example code?
      I am a beginner in the topic of Bluetooth. Thank you in advance for your help!
      Regards, Paul.

    [Polish: https://forum.qt.io/topic/102441/qt-komunikacja-przez-bluetooth ~kshegunov]



  • @Pientashek
    Firstly, i suggest you to read a overview of Qt Bluetooth Api
    https://doc.qt.io/qt-5/qtbluetooth-index.html
    It will provide you a general knowledge of how Qt supports the Bluetooth technology.

    The qt has examples of bluetooth comunication between devices, for example:
    https://doc.qt.io/qt-5/qtbluetooth-btchat-example.html (C++)
    https://doc.qt.io/qt-5/qtbluetooth-chat-example.html (Qml)

    how to detect the module "programmatically" in c ++ (Qt)

    You can check all avaliable bluetooth devices on your system by calling allDevices static method.

    See a example (Using QGuiApplication):

    #include <QGuiApplication>
    #include <QBluetoothLocalDevice>
    #include <QDebug>
    
    int main(int argc, char *argv[])
    {
        QGuiApplication app(argc, argv);
    
        QList<QBluetoothHostInfo> infos = QBluetoothLocalDevice::allDevices();
    
        if (infos.isEmpty()){
            qWarning() << "Missing Bluetooth local device. ";
            return 0;
        }
    
        for(const QBluetoothHostInfo &hostInfo : qAsConst(infos)){
            qDebug() << hostInfo.name() << hostInfo.address(); // name and mac address
        }
    
       // your code
    
        return app.exec();
    }
    


  • @KillerSmath said in Qt Bluetooth communication:

    #include <QGuiApplication>
    #include <QBluetoothLocalDevice>
    #include <QDebug>

    int main(int argc, char *argv[])
    {
    QGuiApplication app(argc, argv);

    QList<QBluetoothHostInfo> infos = QBluetoothLocalDevice::allDevices();
    
    if (infos.isEmpty()){
        qWarning() << "Missing Bluetooth local device. ";
        return 0;
    }
    
    for(const QBluetoothHostInfo &hostInfo : qAsConst(infos)){
        qDebug() << hostInfo.name() << hostInfo.address(); // name and mac address
    

    Thank You for answer, i'll try to do something :)



  • @KillerSmath said in Qt Bluetooth communication:

    @Pientashek
    Firstly, i suggest you to read a overview of Qt Bluetooth Api
    https://doc.qt.io/qt-5/qtbluetooth-index.html
    It will provide you a general knowledge of how Qt supports the Bluetooth technology.

    The qt has examples of bluetooth comunication between devices, for example:
    https://doc.qt.io/qt-5/qtbluetooth-btchat-example.html (C++)
    https://doc.qt.io/qt-5/qtbluetooth-chat-example.html (Qml)

    how to detect the module "programmatically" in c ++ (Qt)

    You can check all avaliable bluetooth devices on your system by calling vidmate.

    See a example (Using QGuiApplication):

    #include <QGuiApplication>
    #include <QBluetoothLocalDevice>
    #include <QDebug>
    
    int main(int argc, char *argv[])
    {
        QGuiApplication app(argc, argv);
    
        QList<QBluetoothHostInfo> infos = QBluetoothLocalDevice::allDevices();
    
        if (infos.isEmpty()){
            qWarning() << "Missing Bluetooth local device. "; 
            return 0;
        }
    
        for(const QBluetoothHostInfo &hostInfo : qAsConst(infos)){
            qDebug() << hostInfo.name() << hostInfo.address(); // name and mac address
        }
    
       // your code
    
        return app.exec();
    }
    

    Happy to help! Thanks for leaving a comment.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.