PySide6.QtBluetooth.QBluetoothServiceDiscoveryAgent¶
- class QBluetoothServiceDiscoveryAgent¶
- The - QBluetoothServiceDiscoveryAgentclass enables you to query for Bluetooth services. More…- Synopsis¶- Methods¶- def - __init__()
- def - error()
- def - errorString()
- def - isActive()
- def - remoteAddress()
- def - setUuidFilter()
- def - uuidFilter()
 - Slots¶- Signals¶- def - canceled()
- def - errorOccurred()
- def - finished()
 - Note - This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE - Detailed Description¶- Warning - This section contains snippets that were automatically translated from C++ to Python and may contain errors. - The discovery process relies on the Bluetooth Service Discovery Process (SDP). The following steps are required to query the services provided by all contactable Bluetooth devices: - create an instance of - QBluetoothServiceDiscoveryAgent,
- connect to either the - serviceDiscovered()or- finished()signals,
- and call - start().
 - def startServiceDiscovery(self): # Create a discovery agent and connect to its signals discoveryAgent = QBluetoothServiceDiscoveryAgent(self) connect(discoveryAgent, SIGNAL(serviceDiscovered(QBluetoothServiceInfo)), self, SLOT(serviceDiscovered(QBluetoothServiceInfo))) # Start a discovery discoveryAgent.start() #... # In your local slot, read information about the found devices def serviceDiscovered(self, service): print("Found service():", service.serviceName()) << '(' << service.device().address().toString() << ')' - By default a minimal service discovery is performed. In this mode, the returned - QBluetoothServiceInfoobjects are guaranteed to contain only device and service UUID information. Depending on platform and device capabilities, other service information may also be available. The minimal service discovery mode relies on cached SDP data of the platform. Therefore it is possible that this discovery does not find a device although it is physically available. In such cases a full discovery must be performed to force an update of the platform cache. However for most use cases a minimal discovery is adequate as it is much quicker and other classes which require up-to-date information such as- connectToService()will perform additional discovery if required. If the full service information is required, pass- FullDiscoveryas the discoveryMode parameter to- start().- This class may internally utilize - QBluetoothDeviceDiscoveryAgentto find unknown devices.- The service discovery may find Bluetooth Low Energy services too if the target device is a combination of a classic and Low Energy device. Those devices are required to advertise their Low Energy services via SDP. If the target device only supports Bluetooth Low Energy services, it is likely to not advertise them via SDP. The - QLowEnergyControllerclass should be utilized to perform the service discovery on Low Energy devices.- On iOS, this class cannot be used because the platform does not expose an API which may permit access to - QBluetoothServiceDiscoveryAgentrelated features.- class Error¶
- This enum describes errors that can occur during service discovery. - Constant - Description - QBluetoothServiceDiscoveryAgent.NoError - No error has occurred. - QBluetoothServiceDiscoveryAgent.PoweredOffError - The Bluetooth adaptor is powered off, power it on before doing discovery. - QBluetoothServiceDiscoveryAgent.InputOutputError - Writing or reading from the device resulted in an error. - QBluetoothServiceDiscoveryAgent.InvalidBluetoothAdapterError - The passed local adapter address does not match the physical adapter address of any local Bluetooth device. - QBluetoothServiceDiscoveryAgent.MissingPermissionsError - The operating system requests permissions which were not granted by the user. - QBluetoothServiceDiscoveryAgent.UnknownError - An unknown error has occurred. 
 - class DiscoveryMode¶
- This enum describes the service discovery mode. - Constant - Description - QBluetoothServiceDiscoveryAgent.MinimalDiscovery - Performs a minimal service discovery. The - QBluetoothServiceInfoobjects returned may be incomplete and are only guaranteed to contain device and service UUID information. Since a minimal discovery relies on cached SDP data it may not find a physically existing device until a- FullDiscoveryis performed.- QBluetoothServiceDiscoveryAgent.FullDiscovery - Performs a full service discovery. 
 - Constructs a new - QBluetoothServiceDiscoveryAgentwith- parent. The search is performed via the local default Bluetooth adapter.- __init__(deviceAdapter[, parent=None])
- Parameters:
- deviceAdapter – - QBluetoothAddress
- parent – - QObject
 
 
 - Constructs a new - QBluetoothServiceDiscoveryAgentfor- deviceAdapterand with- parent.- It uses - deviceAdapterfor the service search. If- deviceAdapteris default constructed the resulting- QBluetoothServiceDiscoveryAgentobject will use the local default Bluetooth adapter.- If a - deviceAdapteris specified that is not a local adapter- error()will be set to- InvalidBluetoothAdapterError. Therefore it is recommended to test the error flag immediately after using this constructor.- Note - On WinRT the passed adapter address will be ignored. - Note - On Android passing any - deviceAdapteraddress is meaningless as Android 6.0 or later does not publish the local Bluetooth address anymore. Subsequently, the passed adapter address can never be matched against the local adapter address. Therefore the subsequent call to- start()will always trigger- InvalidBluetoothAdapterError.- See also - canceled()¶
 - This signal is triggered when the service discovery was canceled via a call to - stop().- clear()¶
 - Clears the results of previous service discoveries and resets - uuidFilter(). This function does nothing during an ongoing service discovery (see- isActive()).- See also - discoveredServices()¶
- Return type:
- .list of QBluetoothServiceInfo 
 
 - Returns the list of all discovered services. - This list of services accumulates newly discovered services from multiple calls to - start(). Unless- clear()is called the list cannot decrease in size. This implies that if a remote Bluetooth device moves out of range in between two subsequent calls to- start()the list may contain stale entries.- Note - The list of services should always be cleared before the discovery mode is changed. - See also - Returns the type of error that last occurred. If the service discovery is done for a single - remoteAddress()it will return errors that occurred while trying to discover services on that device. If the- remoteAddress()is not set and devices are discovered by a scan, errors during service discovery on individual devices are not saved and no signals are emitted. In this case, errors are fairly normal as some devices may not respond to discovery or may no longer be in range. Such errors are suppressed. If no services are returned, it can be assumed no services could be discovered.- Any possible previous errors are cleared upon restarting the discovery. - This signal is emitted when an - erroroccurs. The- errorparameter describes the error that occurred.- errorString()¶
- Return type:
- str 
 
 - Returns a human-readable description of the last error that occurred during the service discovery. - See also - finished()¶
 - This signal is emitted when the Bluetooth service discovery completes. - Unlike the - finished()signal this signal will even be emitted when an error occurred during the service discovery. Therefore it is recommended to check the- errorOccurred()signal to evaluate the success of the service discovery discovery.- isActive()¶
- Return type:
- bool 
 
 - Returns - trueif the service discovery is currently active; otherwise returns- false. An active discovery can be stopped by calling- stop().- remoteAddress()¶
- Return type:
 
 - Returns the remote device address. If - setRemoteAddress()is not called, the function will return a default constructed- QBluetoothAddress.- See also - serviceDiscovered(info)¶
- Parameters:
- info – - QBluetoothServiceInfo
 
 - This signal is emitted when the Bluetooth service described by - infois discovered.- Note - The passed - QBluetoothServiceInfoparameter may contain a Bluetooth Low Energy service if the target device advertises the service via SDP. This is required from device which support both, classic Bluetooth (BaseRate) and Low Energy services.- See also - setRemoteAddress(address)¶
- Parameters:
- address – - QBluetoothAddress
- Return type:
- bool 
 
 - Sets the remote device address to - address. If- addressis default constructed, services will be discovered on all contactable Bluetooth devices. A new remote address can only be set while there is no service discovery in progress; otherwise this function returns false.- On some platforms the service discovery might lead to pairing requests. Therefore it is not recommended to do service discoveries on all devices. This function can be used to restrict the service discovery to a particular device. - See also - setUuidFilter(uuid)¶
- Parameters:
- uuid – - QBluetoothUuid
 
 - This is an overloaded member function, provided for convenience. - Sets the UUID filter to a list containing the single element - uuid. The matching applies to the service’s- ServiceIdand- ServiceClassIdsattributes.- See also - setUuidFilter(uuids)
- Parameters:
- uuids – .list of QBluetoothUuid 
 
 - Sets the UUID filter to - uuids. Only services matching the UUIDs in- uuidswill be returned. The matching applies to the service’s- ServiceIdand- ServiceClassIdsattributes.- An empty UUID list is equivalent to a list containing only - PublicBrowseGroup.- See also - start([mode=QBluetoothServiceDiscoveryAgent.DiscoveryMode.MinimalDiscovery])¶
- Parameters:
- mode – - DiscoveryMode
 
 - Starts service discovery. - modespecifies the type of service discovery to perform.- On some platforms, device discovery may lead to pairing requests. - See also - stop()¶
 - Stops the service discovery process. The - canceled()signal will be emitted once the search has stopped.- uuidFilter()¶
- Return type:
- .list of QBluetoothUuid 
 
 - Returns the UUID filter. - See also