Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Sending HEX data over Bluetooth (Android)



  • Greetings,
    I am trying to send the following Hex string via Bluetooth

    00 02 1b 53 90
    

    and I have tried the following method to do that

        QByteArray hexString;
    
        hexString.append(QByteArray::number(00, 16));
        hexString.append(QByteArray::number(02, 16));
        hexString.append(QByteArray::number(27, 16));
        hexString.append(QByteArray::number(83, 16));
        hexString.append(QByteArray::number(144, 16));
    
        server->sendMessage(hexString);
    

    but whenever I send it then the app gets closed unexpectedly.

    The debug mode shows the following info:
    HEX.JPG

    How can I accomplish it?
    Looking forward to a kind response.


  • Lifetime Qt Champion

    @ahsan737 Is server a valid pointer?



  • @ahsan737 said in Sending HEX data over Bluetooth (Android):

    Greetings,
    I am trying to send the following Hex string via Bluetooth
    00 02 1b 53 90

    and I have tried the following method to do that
    QByteArray hexString;

    hexString.append(QByteArray::number(00, 16));
    hexString.append(QByteArray::number(02, 16));
    hexString.append(QByteArray::number(27, 16));
    hexString.append(QByteArray::number(83, 16));
    hexString.append(QByteArray::number(144, 16));
    
    server->sendMessage(hexString);
    

    As QByteArray::number() documentation says, this will return a string:

    QByteArray::number(144, 16) ==> returns a string with "90"

    This is not what you want to have, try this:

        QByteArray hexString;
    
        hexString.append(quint8(0));
        hexString.append(quint8(2));
        hexString.append(quint8(27));
        hexString.append(quint8(83));
        hexString.append(quint8(144));
    
        server->sendMessage(hexString);
    


  • @KroMignon
    @jsulm Thanks for your kind suggestions. the program crash was because of the invalid pointer. I've fixed that and then the following command did the rest of work

        QByteArray hexString= QByteArray::fromHex("00021b5390");
        socket->write(hexString);
    

Log in to reply