C++ QBluetoothSocket::connectToService挂起在ServiceLookupState上-为什么?
我有一个应用程序,它可以(或应该)作为客户端连接到Android设备上的蓝牙服务。这样做的代码并不复杂,与中给出的示例没有太大区别,尽管它作为类的一部分进行了一些分发 在构造函数中:C++ QBluetoothSocket::connectToService挂起在ServiceLookupState上-为什么?,c++,qt,sockets,bluetooth,C++,Qt,Sockets,Bluetooth,我有一个应用程序,它可以(或应该)作为客户端连接到Android设备上的蓝牙服务。这样做的代码并不复杂,与中给出的示例没有太大区别,尽管它作为类的一部分进行了一些分发 在构造函数中: mBluetoothSocket = new QBluetoothSocket(QBluetoothServiceInfo::RfcommProtocol); 在“waitForServiceConnection”方法中: mBluetoothSocket->connectToService(地址,uuid);
mBluetoothSocket = new QBluetoothSocket(QBluetoothServiceInfo::RfcommProtocol);
在“waitForServiceConnection”方法中:
mBluetoothSocket->connectToService(地址,uuid);
for(无符号i=0;i qDebug()代码本身没有问题-问题在于它位于从某些单元测试调用的库中。从标准Qt控制台应用程序调用时,它工作正常
由于单元测试无法正确处理蓝牙组件,因此这是可以接受的
mBluetoothSocket->connectToService(address, uuid);
for (unsigned i = 0; i < timeout; ++i)
{
QTime delayLimit = QTime::currentTime().addSecs(1);
while( QTime::currentTime() < delayLimit ) QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
qDebug() << "Current socket state is " << mBluetoothSocket->state() << endl;
if (mServiceConnected)
{
return;
}
}
...
}
qDebug() << "Socket state changed to " << socketState << endl;