Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt Bluetooth scanning not working

Tags:

c++

qt

bluetooth

I am implementing a Qt Bluetooth Application for android. my requirements are as follows :

  1. I want to turn the Bluetooth ON

  2. I need to scan for the device which Bluetooth is on for that we need to check.

  3. I need to show all devices that are on in a list.

Currently, my first requirement is to make my code run. :)

I am struggling to scan for devices. Firstly it doesn't find all devices. Secondly, my code shows a blank list. Would appreciate if you could let me know what am I doing wrong?

Here is my code

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()
 {

 }

I searched for related questions but i didn't find proper solution.

Thanks in advance.

like image 211
venkatesh Avatar asked Jan 29 '26 19:01

venkatesh


1 Answers

QtBluetooth only works on Android starting Qt 5.3, if you're using Qt 5.2, it won't work.

Also, did you try to compile basic Qt example?

http://qt-project.org/doc/qt-5/qtbluetooth-btscanner-example.html

If this works by simply opening, compiling and deploying the .pro file from QtCreator, your program should work too!

like image 104
jpo38 Avatar answered Jan 31 '26 11:01

jpo38



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!