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 |
Public Types
enum | Error { NoError, UnknownError, PoweredOffError, InputOutputError, ServiceAlreadyRegisteredError, UnsupportedProtocolError } |
Public Functions
QBluetoothServer(QBluetoothServiceInfo::Protocol serverType, QObject *parent = nullptr) | |
virtual | ~QBluetoothServer() |
void | close() |
QBluetoothServer::Error | error() const |
bool | hasPendingConnections() const |
bool | isListening() const |
bool | listen(const QBluetoothAddress &address = QBluetoothAddress(), quint16 port = 0) |
QBluetoothServiceInfo | listen(const QBluetoothUuid &uuid, const QString &serviceName = QString()) |
int | maxPendingConnections() const |
QBluetoothSocket * | nextPendingConnection() |
QBluetooth::SecurityFlags | securityFlags() const |
QBluetoothAddress | serverAddress() const |
quint16 | serverPort() const |
QBluetoothServiceInfo::Protocol | serverType() const |
void | setMaxPendingConnections(int numConnections) |
void | setSecurityFlags(QBluetooth::SecurityFlags security) |
- 31 public functions inherited from QObject
Signals
void | error(QBluetoothServer::Error error) |
void | newConnection() |
- 2 signals inherited from QObject
Static Public Members
const QMetaObject | staticMetaObject |
- 9 static public members inherited from QObject
Protected Variables
QBluetoothServerPrivate * | d_ptr |
Additional Inherited Members
- 1 property inherited from QObject
- 1 public slot inherited from QObject
- 9 protected functions inherited from QObject
Detailed Description
The QBluetoothServer class uses the RFCOMM or L2cap protocol to communicate with a Bluetooth device.
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.
Constant | Value | Description |
---|---|---|
QBluetoothServer::NoError | 0 | No error. |
QBluetoothServer::UnknownError | 1 | An unknown error occurred. |
QBluetoothServer::PoweredOffError | 2 | The Bluetooth adapter is powered off. |
QBluetoothServer::InputOutputError | 3 | An input output error occurred. |
QBluetoothServer::ServiceAlreadyRegisteredError | 4 | The service or port was already registered |
QBluetoothServer::UnsupportedProtocolError | 5 | The 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.
void QBluetoothServer::close()
QBluetoothServer::Error QBluetoothServer::error() const
[signal]
void QBluetoothServer::error(QBluetoothServer::Error error)
Note: Signal error is overloaded in this class. To connect to this signal by using the function pointer syntax, Qt provides a convenient helper for obtaining the function pointer as shown in this example:
connect(bluetoothServer, QOverload<QBluetoothServer::Error>::of(&QBluetoothServer::error), [=](QBluetoothServer::Error error){ /* ... */ });
bool QBluetoothServer::hasPendingConnections() const
bool QBluetoothServer::isListening() const
Returns true if the server is listening for incoming connections, otherwise false.
bool QBluetoothServer::listen(const QBluetoothAddress &address = QBluetoothAddress(), quint16 port = 0)
QBluetoothServiceInfo QBluetoothServer::listen(const QBluetoothUuid &uuid, const QString &serviceName = QString())
int QBluetoothServer::maxPendingConnections() const
Returns the maximum number of pending connections.
See also setMaxPendingConnections().
[signal]
void QBluetoothServer::newConnection()
QBluetoothSocket *QBluetoothServer::nextPendingConnection()
QBluetooth::SecurityFlags QBluetoothServer::securityFlags() const
See also setSecurityFlags().
QBluetoothAddress QBluetoothServer::serverAddress() const
quint16 QBluetoothServer::serverPort() const
QBluetoothServiceInfo::Protocol QBluetoothServer::serverType() const
void QBluetoothServer::setMaxPendingConnections(int numConnections)
See also maxPendingConnections().
void QBluetoothServer::setSecurityFlags(QBluetooth::SecurityFlags security)
See also securityFlags().