Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/126.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ QBluetoothSocket::connectToService挂起在ServiceLookupState上-为什么?_C++_Qt_Sockets_Bluetooth - Fatal编程技术网

C++ QBluetoothSocket::connectToService挂起在ServiceLookupState上-为什么?

C++ QBluetoothSocket::connectToService挂起在ServiceLookupState上-为什么?,c++,qt,sockets,bluetooth,C++,Qt,Sockets,Bluetooth,我有一个应用程序,它可以(或应该)作为客户端连接到Android设备上的蓝牙服务。这样做的代码并不复杂,与中给出的示例没有太大区别,尽管它作为类的一部分进行了一些分发 在构造函数中: mBluetoothSocket = new QBluetoothSocket(QBluetoothServiceInfo::RfcommProtocol); 在“waitForServiceConnection”方法中: mBluetoothSocket->connectToService(地址,uuid);

我有一个应用程序,它可以(或应该)作为客户端连接到Android设备上的蓝牙服务。这样做的代码并不复杂,与中给出的示例没有太大区别,尽管它作为类的一部分进行了一些分发

在构造函数中:

mBluetoothSocket = new QBluetoothSocket(QBluetoothServiceInfo::RfcommProtocol);
在“waitForServiceConnection”方法中:

mBluetoothSocket->connectToService(地址,uuid);
for(无符号i=0;iqDebug()代码本身没有问题-问题在于它位于从某些单元测试调用的库中。从标准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;