QtBlueTooth在Linux上不起作用 [英] QtBlueTooth not functional on Linux

查看:230
本文介绍了QtBlueTooth在Linux上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个使用Qt 5.7启用了蓝牙LE功能的嵌入式应用程序.我正在开发的设备旨在充当外围设备,它可以广播广告包并允许智能手机连接.

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.

目标板正在运行具有bluez版本5.43(最新版本)的Ubuntu Linux 14.04,因为Qt文档说:在Qt 5.7中,添加了支持外围角色的其他API作为技术预览,后端仅针对Linux实现/BlueZ."因此,我认为Qt蓝牙API正是我所需要的.

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.

但是,当我构建并运行Qt蓝牙示例(Bluetooth低能耗心率服务器示例和Bluetooth扫描仪示例)时,它们都不起作用.我只能得到控制台输出:" qt.bluetooth:虚拟后端正在运行.Qt蓝牙模块不起作用."

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."

我搜索了该错误消息,似乎很多开发人员都收到了该错误消息,因为他们在Windows平台上使用Qt蓝牙API,而qt蓝牙api不支持Windows.但是我正在使用Ubuntu Linux,因此很明显出了点问题,但我不知道到底是什么原因引起的.

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.

我正在尝试:

  1. 启用QtBluetooth日志记录.但没有其他有趣的消息要显示.
  2. 不要使用任何Qt蓝牙API,只需使用命令行工具hciconfig和hcitool即可手动设置广告操作.它实际上有效!我的iPhone可以看到"该设备,并且可以连接到它!

基于我的尝试,我认为我的硬件还可以,蓝牙芯片可以工作,但是我确实需要QtBluetooth API才能正常工作.也许我错过了重要的事情?bluez需要一些配置吗?请帮忙.

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.

推荐答案

好的,最后我设法解决了这个问题.当您通过源代码构建Qt时,它具有一些功能测试功能.如果主机上未安装任何开发包,则测试将失败,并且该功能将无法正常工作.在这种情况下,qt将使用虚拟后端,因此示例应用程序仍可以编译并运行,但没有任何实际用途.

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.

说到qt蓝牙,必需的dev软件包是libbluetooth-dev蓝牙blueman bluez blueus libusb-dev libdbus-1-dev bluez-hcidump bluez-tools(为了防万一,我列出的安装数量超出了所需的数量),请确保将所有这些文件安装在主机上先于.

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.

完成所有准备工作后,我运行configure脚本为Qt生成Makefile.这是我使用的配置脚本:

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    

运行configure脚本后,您将在yourQtSourcePath/qtbase/bin/下获得一个qmake可执行文件,然后可以通过执行以下命令来测试您的qtbluetooth函数:

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

那么您就可以了,只需&&为整个Qt源安装后,qt蓝牙现在可以正常工作了.

then you are good to go, just make && make install for the whole Qt source, qt bluetooth can work properly now.

如果无论如何您都无法通过蓝牙测试(这很可能在您需要交叉编译的情况下,例如我的情况),那么我已经找到了一种解决方法.您仍然需要在make之前安装所有必需的dev软件包,这一次才能通过蓝牙功能测试,您可以使用系统内置的qmake(apt-get install qt5-qmake,>通过运行配置脚本生成的qmake)以与qtconnectivity.pro一起使用.这样,您可以通过蓝牙功能测试并为qtconnectivity模块生成一个Makefile.

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.

修改Makefile,更改QMAKE参数.就我而言,这是结果:

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 

然后,您可以通过make&&交叉编译整个Qt源.进行安装.

Then, you can cross-compile the whole Qt source by make && make install.

我已经测试了解决方法,示例应用程序(heartRate服务器)现在可以正常工作.烦人的消息"qt.bluetooth:虚拟后端正在运行.Qt蓝牙模块不起作用":)

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 :)

这篇关于QtBlueTooth在Linux上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆