问题
I'm developing an embedded application with bluetooth LE function enabled using Qt 5.7. The device I'm developing are meant to act as peripheral role, it can broadcast advertising packets and let smartphones to connect to.
The target board are running with Ubuntu Linux 14.04, with bluez version 5.43 (the latest) Since Qt documentation says "In Qt 5.7, additional API supporting the peripheral role was added as a Technology Preview, with the backend only implemented for Linux/BlueZ." So, I think the Qt bluetooth API are exactly what I need.
But when I build and run the Qt bluetooth examples (BlueTooth Low Energy Heart Rate Server Example and Bluetooth Scanner Example), none of them are working. I can only get console output: "qt.bluetooth: Dummy backend running. Qt Bluetooth module is non-functional."
I googled that error message, it seems many developers get that error message because they are using Qt bluetooth API on windows platform, and qt bluetooth api does not support Windows. But I'm using Ubuntu Linux, so clearly something wrong but I don't know what exactly cause the issue.
What I'm trying:
- Enable QtBluetooth logging. But nothing more interesting message to show.
- Don't use any Qt bluetooth API, just use command line tool hciconfig and hcitool to manually set up an advertising action. And it actually works ! My iPhone can "see" the device, and I can connect to it !
Based on what I'm trying, I think my hardware are OK, the bluetooth chip can work, but I really need the QtBluetooth API to work correctly. Maybe I miss something important ? The bluez need some configuration ? Please help.
回答1:
I've encountered the same problem. When i tried to cross compile Qt framework for my hardware, Bluetooth related libraries showed the same log:
"qt.bluetooth: Dummy backend running. Qt Bluetooth module is non-functional."
The root cause of this issue in my case was in sysroot. It had no Bluetooth includes and libraries. That's why Qt bluetooth test failed to pass.
In this situation i suggest to add -v
flag so it will show complete logs, and you can check exact problem why Qt tests fails.
My problem was solved when i downloaded necessary folders from the device with all libraries and includes and used it as -sysroot
argument. Tests passed successfully and there was no need to use workaround suggested by @colin.
回答2:
OK, finally I've managed to solve the issue. Qt has some feature test functions when you build it by source. If you don't have some development packages installed on the host, the test will fail and the function won't work properly. In this case qt will use dummy backend instead, so the example apps can still compile OK and run, but without any practical usage.
Speaking of the qt bluetooth, the required dev-packages are libbluetooth-dev bluetooth blueman bluez libusb-dev libdbus-1-dev bluez-hcidump bluez-tools (I've list more installs than needed, just in case), make sure install all these on the host BEFORE make.
After I've done all the prepare work, I run the configure script to generate the Makefile for Qt. This is the configure script I use:
#!/bin/sh
./configure \
-v \
-prefix /opt/qt-5.7.0 \
-release \
-opensource \
-xplatform linux-arm-gnueabi-g++ \ # yes, I need to cross-compile
-qt-sql-sqlite \
-qt-zlib \
-qt-pcre \
-no-opengl \
-no-sse2 \
-no-openssl \
-qt-freetype \
-nomake examples \
-nomake tests \
-no-separate-debug-info \
-no-qml-debug \
-pkg-config \
-confirm-license
After running the configure script, you'll get a qmake executable under yourQtSourcePath/qtbase/bin/, then you can test your qtbluetooth function by execute:
qtSourcePath/qtbase/bin/qmake qtSourcePath/qtconnectivity/qtconnectivity.pro
If you see something like:
Checking for bluez... yes
Checking for bluez_le... yes
Checking for linux_crypto_api... yes
then you are good to go, just make && make install for the whole Qt source, qt bluetooth can work properly now.
EDIT:
If by any means you can't pass the bluetooth test (It's very possible when you need to cross-compile, like my case), I've figured out a workaround. You still have to install all the required dev-packages before make, this time in order to pass the bluetooth function test, you can use your system built-in qmake (apt-get install qt5-qmake, NOT the qmake you generated by running configure script) to work with qtconnectivity.pro. This way, you can pass the bluetooth function test and generate a Makefile for qtconnectivity module.
Modify the Makefile, change the QMAKE parameter. In my case, this is the result:
- QMAKE = /usr/lib/x86_64-linux-gnu/qt5/bin/qmake
+ QMAKE = /opt/qt-everywhere-opensource-src-5.7.0/qtbase/bin/qmake
Then, you can cross-compile the whole Qt source by make && make install.
I've test the workaround, the example app (heartRate server) can work properly now. The annoying message "qt.bluetooth: Dummy backend running. Qt Bluetooth module is non-functional" is gone :)
来源:https://stackoverflow.com/questions/40901662/qtbluetooth-not-functional-on-linux