QBluetoothServer#

The QBluetoothServer class uses the RFCOMM or L2cap protocol to communicate with a Bluetooth device. More

Inheritance diagram of PySide6.QtBluetooth.QBluetoothServer

Synopsis#

Functions#

Signals#

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#

QBluetoothServer is used to implement Bluetooth services over RFCOMM or L2cap.

Start listening for incoming connections with listen() . Wait till the newConnection() signal is emitted when a new connection is established, and call nextPendingConnection() to get a QBluetoothSocket for the new connection.

To enable other devices to find your service, create a QBluetoothServiceInfo with the applicable attributes for your service and register it using registerService() . Call serverPort() to get the channel number that is being used.

If the Protocol is not supported by a platform, listen() will return false. Android and WinRT only support RFCOMM for example.

On iOS, this class cannot be used because the platform does not expose an API which may permit access to QBluetoothServer related features.

class PySide6.QtBluetooth.QBluetoothServer(serverType[, parent=None])#
Parameters:

Constructs a bluetooth server with parent and serverType.

PySide6.QtBluetooth.QBluetoothServer.Error#

This enum describes Bluetooth server error types.

Constant

Description

QBluetoothServer.NoError

No error.

QBluetoothServer.UnknownError

An unknown error occurred.

QBluetoothServer.PoweredOffError

The Bluetooth adapter is powered off.

QBluetoothServer.InputOutputError

An input output error occurred.

QBluetoothServer.ServiceAlreadyRegisteredError

The service or port was already registered

QBluetoothServer.UnsupportedProtocolError

The Protocol is not supported on this platform.

QBluetoothServer.MissingPermissionsError

The operating system requests permissions which were not granted by the user.

PySide6.QtBluetooth.QBluetoothServer.close()#

Closes and resets the listening socket. Any already established QBluetoothSocket continues to operate and must be separately closed .

PySide6.QtBluetooth.QBluetoothServer.error()#
Return type:

Error

Returns the last error of the QBluetoothServer .

PySide6.QtBluetooth.QBluetoothServer.errorOccurred(error)#
Parameters:

errorError

This signal is emitted when an error occurs.

See also

error() Error

PySide6.QtBluetooth.QBluetoothServer.hasPendingConnections()#
Return type:

bool

Returns true if a connection is pending, otherwise false.

PySide6.QtBluetooth.QBluetoothServer.isListening()#
Return type:

bool

Returns true if the server is listening for incoming connections, otherwise false.

PySide6.QtBluetooth.QBluetoothServer.listen([address=QBluetoothAddress()[, port=0]])#
Parameters:
Return type:

bool

Start listening for incoming connections to address on port. address must be a local Bluetooth adapter address and port must be larger than zero and not be taken already by another Bluetooth server object. It is recommended to avoid setting a port number to enable the system to automatically choose a port.

Returns true if the operation succeeded and the server is listening for incoming connections, otherwise returns false.

If the server object is already listening for incoming connections this function always returns false. close() should be called before calling this function.

PySide6.QtBluetooth.QBluetoothServer.listen(uuid[, serviceName=""])
Parameters:
Return type:

PySide6.QtBluetooth.QBluetoothServiceInfo

Warning

This section contains snippets that were automatically translated from C++ to Python and may contain errors.

Convenience function for registering an SPP service with uuid and serviceName. Because this function already registers the service, the QBluetoothServiceInfo object which is returned can not be changed any more. To shutdown the server later on it is required to call unregisterService() and close() on this server object.

Returns a registered QBluetoothServiceInfo instance if successful otherwise an invalid QBluetoothServiceInfo . This function always assumes that the default Bluetooth adapter should be used.

If the server object is already listening for incoming connections this function returns an invalid QBluetoothServiceInfo .

For an RFCOMM server this function is equivalent to following code snippet.

<Code snippet "qbluetoothserver.cpp:listen" not found>
<Code snippet "qbluetoothserver.cpp:listen2" not found>
<Code snippet "qbluetoothserver.cpp:listen3" not found>
PySide6.QtBluetooth.QBluetoothServer.maxPendingConnections()#
Return type:

int

Returns the maximum number of pending connections.

PySide6.QtBluetooth.QBluetoothServer.newConnection()#

This signal is emitted when a new connection is available.

The connected slot should call nextPendingConnection() to get a QBluetoothSocket object to send and receive data over the connection.

PySide6.QtBluetooth.QBluetoothServer.nextPendingConnection()#
Return type:

PySide6.QtBluetooth.QBluetoothSocket

Returns a pointer to the QBluetoothSocket for the next pending connection. It is the callers responsibility to delete the pointer.

PySide6.QtBluetooth.QBluetoothServer.securityFlags()#
Return type:

Combination of QBluetooth.Security

Returns the Bluetooth security flags.

PySide6.QtBluetooth.QBluetoothServer.serverAddress()#
Return type:

PySide6.QtBluetooth.QBluetoothAddress

Returns the server address.

PySide6.QtBluetooth.QBluetoothServer.serverPort()#
Return type:

int

Returns the server port number.

PySide6.QtBluetooth.QBluetoothServer.serverType()#
Return type:

Protocol

Returns the type of the QBluetoothServer .

PySide6.QtBluetooth.QBluetoothServer.setMaxPendingConnections(numConnections)#
Parameters:

numConnections – int

Sets the maximum number of pending connections to numConnections. If the number of pending sockets exceeds this limit new sockets will be rejected.

PySide6.QtBluetooth.QBluetoothServer.setSecurityFlags(security)#
Parameters:

security – Combination of QBluetooth.Security

Sets the Bluetooth security flags to security. This function must be called before calling listen() . The Bluetooth link will always be encrypted when using Bluetooth 2.1 devices as encryption is mandatory.

Android only supports two levels of security (secure and non-secure). If this flag is set to NoSecurity the server object will not employ any authentication or encryption. Any other security flag combination will trigger a secure Bluetooth connection.

On macOS, security flags are not supported and will be ignored.

See also

securityFlags()