qbluetoothdeviceinfo servicedata()方法提出了奇怪的问题,字节具有0个值

发布于 2025-01-31 23:31:47 字数 920 浏览 2 评论 0原文

我正在尝试使用qbluetoothdeviceinfo类(QT 6.3)从蓝牙设备中检索服务数据信息,但是当它包含具有0个值的字节时,它将被截断。

例如,我在写为0xff22233000065的蓝牙设备中有服务数据:问题是qbluetoothdeviceinfo的servicedata()方法返回QByTearray,该QbyTearray只有前三个字节FF,22、33,并在找到00时停止。 你们中有人遇到过这样类似的问题吗?

谢谢您提前的

编辑:在这里,我粘贴了我的代码摘录,试图澄清我的问题:

    //...

discoveryAgent = new QBluetoothDeviceDiscoveryAgent();

connect(discoveryAgent, &QBluetoothDeviceDiscoveryAgent::deviceDiscovered,
        this, &BluetoothController::addDevice);
        

//...

void BluetoothController::addDevice(const QBluetoothDeviceInfo &device)
{
    //...
    QBluetoothUuid sId = device.serviceIds().front();
    
    //Here is the problem: instead of having sData composed by 6 bytes
    //as expected in my test (i.e 0xFF 0x22 0x33 0x00 0x00 0x65),
    //sData has size = 3 and has only 0xFF 0x22 0x33
    QByteArray sData = device.serviceData(sId);
    
    //...
}

I am trying to retrieve Service Data information from Bluetooth devices using QBluetoothDeviceInfo class (Qt 6.3), but when it contains bytes with 0 values it gets truncated.

For example I have the Service Data in my bluetooth device written as 0xFF2233000065: the problem is that serviceData() method of QBluetoothDeviceInfo returns a QByteArray that has only the first three bytes FF, 22, 33 and stops when it founds 00.
Any of you has encountered such a similar issue?

Thank you in advance

edit: Here I paste excerpts from my code, trying to clarify my issue:

    //...

discoveryAgent = new QBluetoothDeviceDiscoveryAgent();

connect(discoveryAgent, &QBluetoothDeviceDiscoveryAgent::deviceDiscovered,
        this, &BluetoothController::addDevice);
        

//...

void BluetoothController::addDevice(const QBluetoothDeviceInfo &device)
{
    //...
    QBluetoothUuid sId = device.serviceIds().front();
    
    //Here is the problem: instead of having sData composed by 6 bytes
    //as expected in my test (i.e 0xFF 0x22 0x33 0x00 0x00 0x65),
    //sData has size = 3 and has only 0xFF 0x22 0x33
    QByteArray sData = device.serviceData(sId);
    
    //...
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文