c++ - Qt 蓝牙扫描不工作

标签 c++ qt bluetooth

我正在为 Android 实现 Qt 蓝牙应用程序。我的要求如下:

  1. 我想打开蓝牙

  2. 我需要扫描我们需要检查的蓝牙开启的设备。

  3. 我需要显示列表中的所有设备。

目前,我的第一个要求是让我的代码运行。 :)

我正在努力扫描设备。首先,它没有找到所有设备。其次,我的代码显示了一个空白列表。 如果您能让我知道我做错了什么,将不胜感激?

这是我的代码

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/

相关文章:

c++ - 使用派生类型的C++ Mixin

C++ Qt QFileSystemWatcher 文件上传双

qt - 对从 QML 调用的槽使用来自不同类(或命名空间)的 ENUM

Android 4.0 和 4.1 蓝牙问题。检测损坏的通信和掉线配对

c++ - 如何在 OSX PlaySoftMidi 示例中增加音量。

c++ - 使用 std::string 和 char* 的最烦人的解析实例

ios - Qt XCode iOS 入口点

iphone - 从 View 1 切换到蓝牙设置......不可能吗?

Android 2.1蓝牙SPP转LM058(串口线更换)问题

c++ - 为 GCC 复制 clang 的 __builtin_assume