QBluetoothServer Class

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

Header: #include <QBluetoothServer>
qmake: QT += bluetooth
Since: Qt 5.2
Inherits: QObject

This class was introduced in Qt 5.2.

Public Types

enum Error { NoError, UnknownError, PoweredOffError, InputOutputError, ServiceAlreadyRegisteredError, UnsupportedProtocolError }

Public Functions

QBluetoothServer(QBluetoothServiceInfo::Protocol serverType, QObject *parent = nullptr)
virtual ~QBluetoothServer()
bool isListening() const
int maxPendingConnections() const
  • 16 public functions inherited from QObject
typedef QObjectList

Macros

Additional Inherited Members

  • 1 property inherited from QObject
  • 1 public slot inherited from QObject
  • 1 signal inherited from QObject
  • 5 static public members inherited from QObject
  • 8 protected functions inherited from QObject

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 QBluetoothServiceInfo::registerService(). Call serverPort() to get the channel number that is being used.

If the QBluetoothServiceInfo::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.

See also QBluetoothServiceInfo and QBluetoothSocket.

Member Type Documentation

enum QBluetoothServer::Error

This enum describes Bluetooth server error types.

ConstantValueDescription
QBluetoothServer::NoError0No error.
QBluetoothServer::UnknownError1An unknown error occurred.
QBluetoothServer::PoweredOffError2The Bluetooth adapter is powered off.
QBluetoothServer::InputOutputError3An input output error occurred.
QBluetoothServer::ServiceAlreadyRegisteredError4The service or port was already registered
QBluetoothServer::UnsupportedProtocolError5The Protocol is not supported on this platform.

Member Function Documentation

QBluetoothServer::QBluetoothServer(QBluetoothServiceInfo::Protocol serverType, QObject *parent = nullptr)

Constructs a bluetooth server with parent and serverType.

[virtual] QBluetoothServer::~QBluetoothServer()

Destroys the bluetooth server.

bool QBluetoothServer::isListening() const

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

int QBluetoothServer::maxPendingConnections() const

Returns the maximum number of pending connections.

See also setMaxPendingConnections().