I am implementing a Qt Bluetooth Application for android. my requirements are as follows :
I want to turn the Bluetooth ON
I need to scan for the device which Bluetooth is on for that we need to check.
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.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With