【问题标题】:How to check connection of QBluetoothSocket with paired device如何检查 QBluetoothSocket 与配对设备的连接
【发布时间】:2019-09-29 12:40:57
【问题描述】:
if(socket->peerAddress().toString()!=addressToConnect)

我是这样做的,在哪里

socket - QBluetoothSocket 的对象

addressToConnect - QString 对象包含套接字连接到的地址

但这只有在连接的设备关闭然后再次打开时才有效,有没有办法在不重新打开设备的情况下检查连接,以防它只是断电或类似的事情?

【问题讨论】:

    标签: c++ qt bluetooth qt5 qt5.12


    【解决方案1】:

    如果我理解正确,您想知道设备是否仍处于连接状态?

    根据文档,socekt 类提供了QBluetoothSocket::state()QBlutoothSocket::error() 函数。 它们提供了您可能正在搜索的 QBluetoothSocket::ConnectedStateQBluetoothSocket::RemoteHostClosedError(自 Qt 5.10 起)类型。

    然后,您可以将其与您要连接的地址的检查结合起来。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-19
      • 1970-01-01
      • 2019-12-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-19
      • 1970-01-01
      相关资源
      最近更新 更多