Nominate our 2022 Qt Champions!

QT5.4.1 Bluetooth issue in Linux

  • Hi,

    When trying to use QT Bluetooth API, it fails to find the device

    QBluetoothLocalDevice localDevice;
    // Check if Bluetooth is available on this device
    if (localDevice.isValid()) {
    qDebug("is Valid");
    QBluetoothAddress myAddress = localDevice.address();
    return true;
    } else {
    qDebug("Not Valid");
    return false;

    I am using​ QT5.4.1​ and BlueZ 4.101

    I can use hciconfig , hcitool, rfcomm, sdptool to operate Bluetooth device

    root@am335x-evm:~# hciconfig -a
    hci0: Type: BR/EDR Bus: UART
    BD Address: 34:B1:F7:E1:49:09 ACL MTU: 1021:6 SCO MTU: 180:4
    RX bytes:948 acl:0 sco:0 events:42 errors:0
    TX bytes:1294 acl:0 sco:0 commands:42 errors:0
    Features: 0xff 0xfe 0x2d 0xfe 0xdb 0xff 0x7b 0x87
    Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3
    Link policy: RSWITCH HOLD SNIFF
    Link mode: SLAVE ACCEPT
    Name: 'at-bt'
    Class: 0x4c0100
    Service Classes: Rendering, Capturing, Telephony
    Device Class: Computer, Uncategorized
    HCI Version: (0x7) Revision: 0x0
    LMP Version: (0x7) Subversion: 0xac7c
    Manufacturer: Texas Instruments Inc. (13)

    Is there any known limitation or am I missing something here ?


  • Just to let everyone know, I managed to fix the problem.

    For open source version (meta-qt5), qtconnectivity lacks bluetooth support by default. Trick is to add bluez4 in packageconfig while building qtconnectivity.


  • Just to let you know, Qt's bluetooth support is not great (yet). I have had many many problems with it since it was first introduced a few versions back.

    I ended up having to dig through Qt code to find out what it was doing to diagnose connection issues.

    Once I resolved those in linux, the same connection code doesn't work in OSX.

    After hitting too many problems like this with code paths that were incomplete in Qt or didn't give any sort of actionable or documented error message, I finally just went native for osx and linux.

    This was as of Qt 5.5, and the alpha of 5.6. I haven't tried to use it again.

    Just wanted to give you that warning in case you have a tight deadline like I did. ;)

  • thanks for the heads up ! somehow I also have the same feeling :)

  • @ankurtyagi Yea, in my opinion it's not ready for actual usage. I have tried to use it in 2 different projects now in the last year and a half with disastrous results.

    In my experience I've found Qt to be absolutely the best GUI toolkit ever, but very subpar when dealing with hardware. I had issues with serialport stuff as well when it was new.

    My advice is definitely don't expect Qt hardware stuff to just work easily out of the box like you do with the GUI stuff. :)

  • Yes, Bluetooth support (tested here on OSX and iOS) seems terribly flawed and/or incomplete.

    I wish they wouldn't push out support for new tech as finished when clearly it is not. "Doesn't crash" is not the same as "works".

  • @TOMATO_QT Lol yep, totally agree. We've all done it though. I know I've pushed out "working" code that was so minimally tested I'm surprised it compiled much less actually worked. ;)

  • @ambershark Shame on us all! :-D

  • @ankurtyagi
    how exactly did you add bluez4 to package config for building qtconnectivity?

    I have the very same issue as you do, I built qt for RPI according to and added qtconnectivity by:
    cd ~/raspi/Qt-5.6/qtconnectivity
    ~/raspi/qt5/bin/qmake -r
    sudo make install

  • and my ~/raspi/qt5/bin/qmake -r does not work...while compiling all the stuff for rpi I missed these pretty lines:

               Checking for bluez... no
               Checking for bluez_le... no

    and yet Qt+=bluetooth did not complain (it complained before adding this corrupted compilation)

    bluez is definitely on my Ubuntu 15.10 x64:

               pkg-config --modversion bluez

    I studyed this - - not my case. Looks more like this but I definitely have libdbus-1-dev

    after doing /path/to/your/qmake -d >qmake.log 2>&1 I have these nice lines:

        DEBUG 1: /home/hap/raspi/qt5/mkspecs/features/link_pkgconfig.prf:10: test function returned false
        DEBUG 1: /home/hap/raspi/qt5/mkspecs/features/link_pkgconfig.prf:10: AND
        DEBUG 1: /home/hap/raspi/qt5/mkspecs/features/link_pkgconfig.prf:10: evaluating test function "error"
        DEBUG 1: /home/hap/raspi/qt5/mkspecs/features/link_pkgconfig.prf:10: calling built-in error("bluez development package not found")
        Project ERROR: bluez development package not found

    well, link_pkgconfig.prf on line 10 has

        !packagesExist($$PKGCONFIG_LIB): error("$$PKGCONFIG_LIB development package not found")

    and how am I to fix this?..

    sorry if it goes offtopic, but the problem was detected just according to the topic title

  • solution for my case (compiling qtconnectivity for RPI) is here

    and usb dongles from CSR are detected ok

  • @Haponov

    sorry for late response. This is how I configure it

    PROFILES="ls /home/qtconnectivity/5.4.1-r0/qtconnectivity-opensource-src-5.4.1/*.pro"

    export QMAKE_MAKE_ARGS=" MAKEFLAGS='-j 4' OE_QMAKE_COMPILER='arm-linux-gnueabihf-gcc -march=armv7-a -marm -mthumb-interwork -mfloat-abi=hard -mfpu=neon -mtune=cortex-a8 --sysroot=/home/external-linaro-toolchain/sysroots/am335x-evm' OE_QMAKE_CC='arm-linux-gnueabihf-gcc -march=armv7-a -marm -mthumb-interwork -mfloat-abi=hard -mfpu=neon -mtune=cortex-a8 --sysroot=/home/external-linaro-toolchain/sysroots/am335x-evm' OE_QMAKE_CXX='arm-linux-gnueabihf-g++ -march=armv7-a -marm -mthumb-interwork -mfloat-abi=hard -mfpu=neon -mtune=cortex-a8 --sysroot=/home/external-linaro-toolchain/sysroots/am335x-evm' OE_QMAKE_CFLAGS=' -isystem/home/gcc-4.7.3/gcc-linaro-arm-linux-gnueabihf-4.7-2013.03-20130313_linux/arm-linux-gnueabihf/include -fstack-protector -O2 -pipe -g -feliminate-unused-debug-types' OE_QMAKE_CXXFLAGS=' -isystem/home/gcc-4.7.3/gcc-linaro-arm-linux-gnueabihf-4.7-2013.03-20130313_linux/arm-linux-gnueabihf/include -fstack-protector -O2 -pipe -g -feliminate-unused-debug-types' OE_QMAKE_LINK='arm-linux-gnueabihf-g++ -march=armv7-a -marm -mthumb-interwork -mfloat-abi=hard -mfpu=neon -mtune=cortex-a8 --sysroot=/home/external-linaro-toolchain/sysroots/am335x-evm' OE_QMAKE_LDFLAGS=' -L/home/gcc-4.7.3/gcc-linaro-arm-linux-gnueabihf-4.7-2013.03-20130313_linux/arm-linux-gnueabihf/lib -Wl,-rpath-link,/home/gcc-4.7.3/gcc-linaro-arm-linux-gnueabihf-4.7-2013.03-20130313_linux/arm-linux-gnueabihf/lib -Wl,-O1 -Wl,--hash-style=gnu' OE_QMAKE_AR='arm-linux-gnueabihf-ar' OE_QMAKE_STRIP='echo' OE_QMAKE_WAYLAND_SCANNER='/home/external-linaro-toolchain/sysroots/i686-linux/usr/bin/wayland-scanner' OE_QMAKE_INCDIR_QT='/home/external-linaro-toolchain/sysroots/am335x-evm//usr/include/qt5' "

    /home/i686-linux/usr/bin/qt5/qmake -makefile -o Makefile $QMAKE_VARSUBST_PRE $PROFILES

Log in to reply