连接到某些蓝牙LE设备会破坏OSX上的Qt应用程序

时间:2015-10-21 18:41:07

标签: macos qt bluetooth-lowenergy

我正在OSX上开发一个Qt应用程序,它扫描并连接到蓝牙低功耗设备。由于在Qt中缺少必要的API来访问广告中的制造商特定数据,我必须连接到扫描期间发现的每个设备,以检查它是否是我正在寻找的设备类型。我现在的问题是,当连接到某些设备时,我可以成功获取有关制造商和序列号的信息;但是当连接到其他设备时,应用程序就会崩溃。

调用QLowEnergyController的方法connectToDevice()时发生崩溃。以下是跟踪:

2015-10-21 11:33:19.875 MyApp[24076:1272507] -[OS_dispatch_mach performNextRequest]: unrecognized selector sent to instance 0x7fe6cb7bbc40
2015-10-21 11:33:19.941 MyApp[24076:1272507] An uncaught exception was raised
2015-10-21 11:33:19.941 MyApp[24076:1272507] -[OS_dispatch_mach performNextRequest]: unrecognized selector sent to instance 0x7fe6cb7bbc40
2015-10-21 11:33:19.941 MyApp[24076:1272507] (
    0   CoreFoundation                      0x00007fff8afc3bd2 __exceptionPreprocess + 178
    1   libobjc.A.dylib                     0x00007fff986c2dd4 objc_exception_throw + 48
    2   CoreFoundation                      0x00007fff8b02d0ed -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
    3   CoreFoundation                      0x00007fff8af343d1 ___forwarding___ + 1009
    4   CoreFoundation                      0x00007fff8af33f58 _CF_forwarding_prep_0 + 120
    5   QtBluetooth                         0x0000000104d23588 -[OSXBTCentralManager peripheral:didUpdateValueForCharacteristic:error:] + 760
    6   CoreBluetooth                       0x00007fff9356d9ee -[CBCentralManager xpcConnection:didReceiveMsg:args:] + 149
    7   CoreBluetooth                       0x00007fff935777de __34-[CBXpcConnection handleMsg:args:]_block_invoke + 77
    8   libdispatch.dylib                   0x00007fff887498ff _dispatch_call_block_and_release + 12
    9   libdispatch.dylib                   0x00007fff8873e453 _dispatch_client_callout + 8
    10  libdispatch.dylib                   0x00007fff88751c1c _dispatch_main_queue_callback_4CF + 1685
    11  CoreFoundation                      0x00007fff8af79789 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
    12  CoreFoundation                      0x00007fff8af3873d __CFRunLoopRun + 1949
    13  CoreFoundation                      0x00007fff8af37d38 CFRunLoopRunSpecific + 296
    14  HIToolbox                           0x00007fff947e9d55 RunCurrentEventLoopInMode + 235
    15  HIToolbox                           0x00007fff947e9b8f ReceiveNextEventCommon + 432
    16  HIToolbox                           0x00007fff947e99cf _BlockUntilNextEventMatchingListInModeWithFilter + 71
    17  AppKit                              0x00007fff8b72df3a _DPSNextEvent + 1067
    18  AppKit                              0x00007fff8b72d369 -[NSApplication _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 454
    19  AppKit                              0x00007fff8b721ecc -[NSApplication run] + 682
    20  libqcocoa.dylib                     0x000000010508408d _ZN21QCocoaEventDispatcher13processEventsE6QFlagsIN10QEventLoop17ProcessEventsFlagEE + 2189
    21  QtCore                              0x00000001042c107d _ZN10QEventLoop4execE6QFlagsINS_17ProcessEventsFlagEE + 381
    22  QtCore                              0x00000001042c3f5a _ZN16QCoreApplication4execEv + 346
    23  MyApp                              0x00000001034bdf3f main + 2319
    24  MyApp                              0x00000001034bd1e4 start + 52
)
2015-10-21 11:33:19.967 MyApp[24076:1272507] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[OS_dispatch_mach performNextRequest]: unrecognized selector sent to instance 0x7fe6cb7bbc40'
*** First throw call stack:
(
    0   CoreFoundation                      0x00007fff8afc3bd2 __exceptionPreprocess + 178
    1   libobjc.A.dylib                     0x00007fff986c2dd4 objc_exception_throw + 48
    2   CoreFoundation                      0x00007fff8b02d0ed -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
    3   CoreFoundation                      0x00007fff8af343d1 ___forwarding___ + 1009
    4   CoreFoundation                      0x00007fff8af33f58 _CF_forwarding_prep_0 + 120
    5   QtBluetooth                         0x0000000104d23588 -[OSXBTCentralManager peripheral:didUpdateValueForCharacteristic:error:] + 760
    6   CoreBluetooth                       0x00007fff9356d9ee -[CBCentralManager xpcConnection:didReceiveMsg:args:] + 149
    7   CoreBluetooth                       0x00007fff935777de __34-[CBXpcConnection handleMsg:args:]_block_invoke + 77
    8   libdispatch.dylib                   0x00007fff887498ff _dispatch_call_block_and_release + 12
    9   libdispatch.dylib                   0x00007fff8873e453 _dispatch_client_callout + 8
    10  libdispatch.dylib                   0x00007fff88751c1c _dispatch_main_queue_callback_4CF + 1685
    11  CoreFoundation                      0x00007fff8af79789 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
    12  CoreFoundation                      0x00007fff8af3873d __CFRunLoopRun + 1949
    13  CoreFoundation                      0x00007fff8af37d38 CFRunLoopRunSpecific + 296
    14  HIToolbox                           0x00007fff947e9d55 RunCurrentEventLoopInMode + 235
    15  HIToolbox                           0x00007fff947e9b8f ReceiveNextEventCommon + 432
    16  HIToolbox                           0x00007fff947e99cf _BlockUntilNextEventMatchingListInModeWithFilter + 71
    17  AppKit                              0x00007fff8b72df3a _DPSNextEvent + 1067
    18  AppKit                              0x00007fff8b72d369 -[NSApplication _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 454
    19  AppKit                              0x00007fff8b721ecc -[NSApplication run] + 682
    20  libqcocoa.dylib                     0x000000010508408d _ZN21QCocoaEventDispatcher13processEventsE6QFlagsIN10QEventLoop17ProcessEventsFlagEE + 2189
    21  QtCore                              0x00000001042c107d _ZN10QEventLoop4execE6QFlagsINS_17ProcessEventsFlagEE + 381
    22  QtCore                              0x00000001042c3f5a _ZN16QCoreApplication4execEv + 346
    23  MyApp                              0x00000001034bdf3f main + 2319
    24  MyApp                              0x00000001034bd1e4 start + 52
)
libc++abi.dylib: terminating with uncaught exception of type NSException
The program has unexpectedly finished.

我有几个问题要问:

  1. 哪种BT设备或设置拒绝/过滤传入连接?当使用LightBlue连接到那些BLE设备时,它会说“外围设备在被询问时断开连接”,但LightBlue不会崩溃。

  2. 我们可以将Qt的Bluetooth DiscoveryAgent设置为仅扫描低能耗设备吗?没有在文件中看到它但仍想问。

  3. 由于崩溃似乎发生在Qt库中,我如何捕获该异常并忽略该设备?我做了以下不起作用。

    try { m_controller->connectToDevice(); }
    catch(...) {  //Log("UNKNOWN EXCEPTION");  }
    
  4. 如果有人能提供有关此问题或上述问题的信息,我将不胜感激。问题可能是具体的,但问题的答案可以帮助我或其他人。感谢。

0 个答案:

没有答案