我正在为 Android 实现 Qt 蓝牙应用程序。我的要求如下:
我想打开蓝牙
我需要扫描我们需要检查的蓝牙开启的设备。
我需要显示列表中的所有设备。
目前,我的第一个要求是让我的代码运行。 :)
我正在努力扫描设备。首先,它没有找到所有设备。其次,我的代码显示了一个空白列表。 如果您能让我知道我做错了什么,将不胜感激?
这是我的代码
Listview::Listview(QWidget *parent):QDialog(parent)
{
listModel = new QStringListModel(*stringList, NULL);
stringList = new QStringList();
BluetoothMain *btmain = BluetoothMain::getInstance();
connect(btmain,SIGNAL(discovered(QString,QString,bool)),this,
SLOT(addToList(QString,QString,bool)));
btmain->startScan();
qDebug()<<"bluetooth is scanning the list";
// list_add->setModel(listModel);
// list_add->show();
}
/*
for(int i=0;i<100;i++)
{
stringList->append(QString::number(i)+"hi everyone");
}
list_add->setModel(listModel);
list_add->show();
*/
void Listview::addToList(QString address,QString name,bool paired)
{
list_add->setModel(listModel);
stringList->append(address);
stringList->append(name);
stringList->append("hi");
list_add->show();
}
Listview::~Listview()
{
}
我搜索了相关问题,但没有找到合适的解决方案。
提前致谢。
最佳答案
QtBluetooth 仅适用于 Android starting Qt 5.3 ,如果您使用的是 Qt 5.2,它将无法工作。
此外,您是否尝试编译基本的 Qt 示例?
http://qt-project.org/doc/qt-5/qtbluetooth-btscanner-example.html
如果仅通过从 QtCreator 打开、编译和部署 .pro 文件就可以工作,那么您的程序也应该可以工作!
关于c++ - Qt 蓝牙扫描不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23026265/