Stopping Bluetooth Service discovery crashes the App
-
Hi All,
Im trying to do a bluetooth service discovery in an android phone using the Bluetooth Service Discovery Agent. My problem is that if I stop the bluetooth scan mid-way, my app crashes. Does anyone have any idea why? Or how to stop an ongoing bluetooth service discovery?
Some of my code is as below:
@void BtScan:: localDeviceInfo()
{
QBluetoothLocalDevice localBluetoothDevice;
QString localBluetoothDeviceName;void BtScan::startDiscovery() {
if(localBluetoothDevice.isValid())
{
localBluetoothDevice.setHostMode(QBluetoothLocalDevice::HostConnectable);
}
serviceDiscoveryAgent = new QBluetoothServiceDiscoveryAgent(this);
serviceDiscoveryAgent->clear();
serviceDiscoveryAgent->setUuidFilter(QBluetoothUuid(QBluetoothUuid::SerialPort));
serviceDiscoveryAgent->start(QBluetoothServiceDiscoveryAgent::FullDiscovery);}
void BtScan :: stopDiscovery()
{
if(serviceDiscoveryAgent->isActive())
{
serviceDiscoveryAgent->stop();
}
}
@If I comment out the serviceDiscoveryAgent->stop(); line, the program works fine , discovers bluetooth devices etc, (but obviously the scanning continues even after I have pressed stop). If I include the line, when i press stop, the app crashes.
Does anyone have any idea why? Or another way to stop an ongoing bluetooth service discovery?
Thanks