- 
    
Bug
 - 
    Resolution: Unresolved
 - 
    
P2: Important
 - 
    None
 - 
    5.15.2, 6.2.0
 - 
    None
 
I have code that trying detect that there is bluetooth support on Linux system.
I tried two variants:
bool isBluetoothSupported1() const { QBluetoothLocalDevice dev; return dev.isValid(); } bool isBluetoothSupported2() const { return !QBluetoothLocalDevice::allDevices().isEmpty(); }
Both works just fine on Arch Linux, and without running `bluetooth.serivce` (part of bluez 5.x) reports that bluetooth not supported.
But on Ubuntu Linux (21.04 and 21.10) both variants hangs for 60 seconds or so.
Here backtrace:
(gdb) bt
#0  __futex_abstimed_wait_common64 (private=0, cancel=true, abstime=0x0, op=393, expected=0, 
    futex_word=0x555558054080) at futex-internal.c:57
#1  __futex_abstimed_wait_common (cancel=true, private=0, abstime=0x0, clockid=0, expected=0, 
    futex_word=0x555558054080) at futex-internal.c:87
#2  __GI___futex_abstimed_wait_cancelable64 (futex_word=futex_word@entry=0x555558054080, 
    expected=expected@entry=0, clockid=clockid@entry=0, abstime=abstime@entry=0x0, 
    private=private@entry=0) at futex-internal.c:139
#3  0x00007ffff5b8d920 in __pthread_cond_wait_common (abstime=0x0, clockid=0, 
    mutex=0x555558054030, cond=0x555558054058) at pthread_cond_wait.c:504
#4  ___pthread_cond_wait (cond=0x555558054058, mutex=0x555558054030) at pthread_cond_wait.c:628
#5  0x00007ffff6107abb in QWaitConditionPrivate::wait (deadline=..., deadline=..., 
    this=0x555558054030) at thread/qwaitcondition_unix.cpp:146
#6  QWaitCondition::wait (this=this@entry=0x555557ac8590, mutex=mutex@entry=0x555557ac8588, 
    deadline=...) at thread/qwaitcondition_unix.cpp:225
#7  0x00007ffff3e824b6 in QDBusPendingCallPrivate::waitForFinished (this=0x555557ac8550)
    at ../../include/QtCore/../../src/corelib/kernel/qdeadlinetimer.h:68
#8  0x00007ffff3e82681 in QDBusPendingCall::waitForFinished (this=this@entry=0x7fffffff8840)
    at ./src/dbus/qdbuspendingcall.cpp:339
#9  0x00007ffff78662d4 in isBluez5 () at bluez/bluez5_helper.cpp:79
#10 0x00007ffff789dfbb in QBluetoothLocalDevicePrivate::QBluetoothLocalDevicePrivate (
    this=0x555557a99860, q=0x7fffffff8980, address=...) at qbluetoothlocaldevice_bluez.cpp:664
#11 0x00007ffff789e048 in QBluetoothLocalDevice::QBluetoothLocalDevice (this=0x7fffffff8980, 
    parent=<optimized out>) at qbluetoothlocaldevice_bluez.cpp:71
In log I see this:
unknown:0: QDBusConnectionPrivate(0x555ad9105e80) Adding rule: "type='signal',sender='org.freedesktop.DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',arg0='org.bluez'"
unknown:0: QDBusConnectionPrivate(0x555ad9105e80) sending message: QDBusMessage(type=MethodCall, service="org.freedesktop.DBus", path="/org/freedesktop/DBus", interface="org.freedesktop.DBus", member="GetNameOwner", signature="", contents=("org.bluez") )
unknown:0: QDBusConnectionPrivate(0x7f8768002560) got message reply: QDBusMessage(type=MethodReturn, service="org.freedesktop.DBus", signature="", contents=() )
unknown:0: QDBusConnectionPrivate(0x555ad9105e80) got message reply: QDBusMessage(type=Error, service="org.freedesktop.DBus", error name="org.freedesktop.DBus.Error.NameHasNoOwner", error message="Could not get owner of name 'org.bluez': no such name", signature="s", contents=("Could not get owner of name 'org.bluez': no such name") )
unknown:0: QDBusConnectionPrivate(0x555ad9105e80) sending message: QDBusMessage(type=MethodCall, service="org.bluez", path="/", interface="org.freedesktop.DBus.ObjectManager", member="GetManagedObjects", signature="", contents=() )
unknown:0: QDBusConnectionPrivate(0x555ad9105e80) got message reply: QDBusMessage(type=Error, service="org.freedesktop.DBus", error name="org.freedesktop.DBus.Error.TimedOut", error message="Failed to activate service 'org.bluez': timed out (service_start_timeout=25000ms)", signature="s", contents=("Failed to activate service 'org.bluez': timed out (service_start_timeout=25000ms)") )
unknown:0: QDBusConnectionPrivate(0x555ad9105e80) sending message: QDBusMessage(type=MethodCall, service="org.freedesktop.DBus", path="/org/freedesktop/DBus", interface="org.freedesktop.DBus", member="GetNameOwner", signature="", contents=("org.bluez") )
unknown:0: QDBusConnectionPrivate(0x555ad9105e80) got message reply: QDBusMessage(type=Error, service="org.freedesktop.DBus", error name="org.freedesktop.DBus.Error.NameHasNoOwner", error message="Could not get owner of name 'org.bluez': no such name", signature="s", contents=("Could not get owner of name 'org.bluez': no such name") )
unknown:0: QDBusConnectionPrivate(0x555ad9105e80) sending message: QDBusMessage(type=MethodCall, service="org.bluez", path="/", interface="org.bluez.Manager", member="ListAdapters", signature="", contents=() )
unknown:0: QDBusConnectionPrivate(0x555ad9105e80) got message reply: QDBusMessage(type=Error, service="org.freedesktop.DBus", error name="org.freedesktop.DBus.Error.TimedOut", error message="Failed to activate service 'org.bluez': timed out (service_start_timeout=25000ms)", signature="s", contents=("Failed to activate service 'org.bluez': timed out (service_start_timeout=25000ms)") )
unknown:0: Cannot find a running Bluez. Please check the Bluez installation.
unknown:0: QDBusConnectionPrivate(0x555ad9105e80) Removing rule: "type='signal',sender='org.freedesktop.DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',arg0='org.bluez'"
unknown:0: QDBusConnectionPrivate(0x555ad9105e80) Adding rule: "type='signal',sender='org.freedesktop.DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',arg0='org.bluez'"
unknown:0: QDBusConnectionPrivate(0x555ad9105e80) sending message: QDBusMessage(type=MethodCall, service="org.freedesktop.DBus", path="/org/freedesktop/DBus", interface="org.freedesktop.DBus", member="GetNameOwner", signature="", contents=("org.bluez") )
unknown:0: QDBusConnectionPrivate(0x555ad9105e80) got message reply: QDBusMessage(type=Error, service="org.freedesktop.DBus", error name="org.freedesktop.DBus.Error.NameHasNoOwner", error message="Could not get owner of name 'org.bluez': no such name", signature="s", contents=("Could not get owner of name 'org.bluez': no such name") )
unknown:0: QDBusConnectionPrivate(0x555ad9105e80) sending message: QDBusMessage(type=MethodCall, service="org.bluez", path="/", interface="org.bluez.Manager", member="DefaultAdapter", signature="", contents=() )
unknown:0: QDBusConnectionPrivate(0x555ad9105e80) got message reply: QDBusMessage(type=Error, service="org.freedesktop.DBus", error name="org.freedesktop.DBus.Error.TimedOut", error message="Failed to activate service 'org.bluez': timed out (service_start_timeout=25000ms)", signature="s", contents=("Failed to activate service 'org.bluez': timed out (service_start_timeout=25000ms)") )
unknown:0: QDBusConnectionPrivate(0x555ad9105e80) Removing rule: "type='signal',sender='org.freedesktop.DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',arg0='org.bluez'"
Not sure, may be this documentation bug. It would be nice to document that QBluetoothLocalDevice::allDevices and QBluetoothLocalDevice::QBluetoothLocalDevice
can hang on huge interval of time and you need call them in separate thread.
I tested on fresh install of Ubuntu 21.10 without any changes in configuration,
just install qt related packages. So this issues should be easy to reproduce.