无法让QT蓝牙模块与虚拟盒Ubuntu一起使用
我使用C ++和QML创建了一个使用QT Creator 4.14.0(QT 5.15.2)的小程序。我正在使用Windows 10系统上的虚拟框在Ubuntu上创建,构建和运行该程序。根据我在网上找到的说明,我已经在虚拟Ubuntu系统上安装了Bluez和其他蓝牙软件包,并且我可以在Ubuntu操作系统中使用蓝牙,我可以使用蓝牙Quick-Tray项目扫描设备,并且可以找到它的内容应该找到的,蓝牙适配器起作用。
但是,当我运行程序时,我会在应用程序输出“ qt.bluetooth:虚拟后端运行。输出)。从我的研究中我可以收集的东西似乎QT认为系统无法支持蓝牙,并使用“虚拟存根”代替实际的工作代码。我已经研究了如何解决这个问题,但是找不到可以应用于自己的代码/设置的任何东西。我会感谢我能获得的任何帮助。
这是相关代码:
// this is bluetooth_scanner.h
#ifndef BLUETOOTH_SCANNER_H
#define BLUETOOTH_SCANNER_H
#include <QObject>
#include <QBluetoothDeviceDiscoveryAgent>
#include <QBluetoothDeviceInfo>
#include <QDir>
#include <QTextStream>
class bluetooth_scanner : public QObject
{
Q_OBJECT
public:
bluetooth_scanner();
void startDeviceDiscovery();
public slots:
void deviceDiscovered(const QBluetoothDeviceInfo &device);
};
#endif // BLUETOOTH_SCANNER_H
// this is bluetooth_scanner.cpp
#include "bluetooth_scanner.h"
// constructor
bluetooth_scanner::bluetooth_scanner()
{
}
void bluetooth_scanner::startDeviceDiscovery()
{
// Create a discovery agent and connect to its signals
QBluetoothDeviceDiscoveryAgent *discoveryAgent = new QBluetoothDeviceDiscoveryAgent(); // was 'this' inside parantheses, got build error, removed == no build error
QObject::connect(discoveryAgent, SIGNAL(deviceDiscovered(QBluetoothDeviceInfo)),this, SLOT(deviceDiscovered(QBluetoothDeviceInfo)));
// Start a discovery
discoveryAgent->start();
}
// In your local slot, read information about the found devices
void bluetooth_scanner::deviceDiscovered(const QBluetoothDeviceInfo &device)
{
// init QT printing
QTextStream out(stdout);
out << "Found new device:" << device.name() << '(' << device.address().toString() << ')' << endl;
}
// this is main.cpp
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <bluetooth_scanner.h>
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
const QUrl url(QStringLiteral("qrc:/main.qml"));
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
&app, [url](QObject *obj, const QUrl &objUrl) {
if (!obj && url == objUrl)
QCoreApplication::exit(-1);
}, Qt::QueuedConnection);
engine.load(url);
// test bluetooth C++ scan function
bluetooth_scanner *bt_scan = new bluetooth_scanner();
bt_scan->startDeviceDiscovery();
return app.exec();
}
I have created a small program using QT creator 4.14.0 (QT 5.15.2), using c++ and QML. I am creating, building and running the program on Ubuntu using Virtual box on a windows 10 system. I have installed bluez and other bluetooth packages on the virtual Ubuntu system as per instructions I've found online, and I have bluetooth working in the Ubuntu operating system, I can scan for devices using the Bluetooth quick-tray item and it finds what it's supposed to find, the bluetooth adapter works.
However, when I run my program I get the the following under Application output "qt.bluetooth: Dummy backend running. Qt Bluetooth module is non-functional.", and the bluetooth scan never starts (no further output). From what I can gather by research it seems like QT thinks that the system can not support Bluetooth, and uses a "dummy stub" in lieu of the actual working code. I have researched what I can about how to resolve this, but I can not find anything I can apply to my own code/setup. I would be appreciative of any help I can get.
Here's the relevant code:
// this is bluetooth_scanner.h
#ifndef BLUETOOTH_SCANNER_H
#define BLUETOOTH_SCANNER_H
#include <QObject>
#include <QBluetoothDeviceDiscoveryAgent>
#include <QBluetoothDeviceInfo>
#include <QDir>
#include <QTextStream>
class bluetooth_scanner : public QObject
{
Q_OBJECT
public:
bluetooth_scanner();
void startDeviceDiscovery();
public slots:
void deviceDiscovered(const QBluetoothDeviceInfo &device);
};
#endif // BLUETOOTH_SCANNER_H
// this is bluetooth_scanner.cpp
#include "bluetooth_scanner.h"
// constructor
bluetooth_scanner::bluetooth_scanner()
{
}
void bluetooth_scanner::startDeviceDiscovery()
{
// Create a discovery agent and connect to its signals
QBluetoothDeviceDiscoveryAgent *discoveryAgent = new QBluetoothDeviceDiscoveryAgent(); // was 'this' inside parantheses, got build error, removed == no build error
QObject::connect(discoveryAgent, SIGNAL(deviceDiscovered(QBluetoothDeviceInfo)),this, SLOT(deviceDiscovered(QBluetoothDeviceInfo)));
// Start a discovery
discoveryAgent->start();
}
// In your local slot, read information about the found devices
void bluetooth_scanner::deviceDiscovered(const QBluetoothDeviceInfo &device)
{
// init QT printing
QTextStream out(stdout);
out << "Found new device:" << device.name() << '(' << device.address().toString() << ')' << endl;
}
// this is main.cpp
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <bluetooth_scanner.h>
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
const QUrl url(QStringLiteral("qrc:/main.qml"));
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
&app, [url](QObject *obj, const QUrl &objUrl) {
if (!obj && url == objUrl)
QCoreApplication::exit(-1);
}, Qt::QueuedConnection);
engine.load(url);
// test bluetooth C++ scan function
bluetooth_scanner *bt_scan = new bluetooth_scanner();
bt_scan->startDeviceDiscovery();
return app.exec();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论