关于:qt.bluetooth: Dummy backend running. Qt Bluetooth module is non-functional.报错。

本人导致的原因MinGW对window原生API支持的问题

我使用的编译环境是Desktop Qt 6.5.3 MinGW 64-bit 会导致蓝牙搜素函数无效在桌面端,所以是window桌面端兼容有问题。切换成MSVC编译器进去编译就可以正常使用。这里本人需要使用MinGW做跨平台。所以后期考虑,MinGW看能不能调用三方库来进行对蓝牙的一个调用。
下面是搜索蓝牙设备的搜索函数:

//discoveryAgent = new QBluetoothDeviceDiscoveryAgent();  //搜寻周围的蓝牙设备
void BluetoothProxy::startSearch()
{
    
    
    qDebug() << "开始搜索设备";

    QBluetoothLocalDevice::HostMode mode = localDevice->hostMode();
    qDebug() << "初始蓝牙模式:" << mode;

    if(mode == QBluetoothLocalDevice::HostPoweredOff){
    
    
        localDevice->powerOn();  // 打开本地的蓝牙设备
        qDebug() << "尝试打开设备";

        // 等待一段时间以确保设备有时间打开
        QThread::sleep(2);  // 睡眠2秒

        mode = localDevice->hostMode();
        qDebug() << "调用 powerOn 后蓝牙模式:" << mode;

        if(mode == QBluetoothLocalDevice::HostPoweredOff){
    
    
            qDebug() << "未能成功打开设备";
            return;
        }
    } else {
    
    
        qDebug() << "设备已打开或处于其他模式";
    }

    // 确认 discoveryAgent 已启动
    qDebug() << "启动 discovery agent...";
    discoveryAgent->start(QBluetoothDeviceDiscoveryAgent::LowEnergyMethod);
}

猜你喜欢

转载自blog.csdn.net/m0_45953836/article/details/140175334