QBluetoothSocket ClassThe QBluetoothSocket class enables connection to a Bluetooth device running an RFCOMM server. More... #include <QBluetoothSocket> Inherits: QIODevice. Public Types
Public Functions
Reimplemented Public Functions
Signals
Protected Functions
Reimplemented Protected Functions
Additional Inherited Members
Detailed DescriptionThe QBluetoothSocket class enables connection to a Bluetooth device running an RFCOMM server. QBluetoothSocket supports two socket types, L2CAP and RFCOMM. L2CAP is a low level datagram-oriented Bluetooth socket. RFCOMM is a reliable, stream-oriented socket. RFCOMM sockets emulate an RS-232 serial port. To create a connection to a Bluetooth service, create a socket of the appropriate type and call connectToService() passing the Bluetooth address and port number. QBluetoothSocket will emit the connected() signal when the connection is established. Member Type Documentation
|
Constant | Value | Description |
---|---|---|
QBluetoothSocket::UnknownSocketError | QAbstractSocket::UnknownSocketError | An unknown error has occurred. |
QBluetoothSocket::NoSocketError | -2 | No error. Used for testing. |
QBluetoothSocket::ConnectionRefusedError | QAbstractSocket::ConnectionRefusedError | Connection refused or device not available. |
QBluetoothSocket::RemoteHostClosedError | QAbstractSocket::RemoteHostClosedError | The remote host closed the socket |
QBluetoothSocket::HostNotFoundError | QAbstractSocket::HostNotFoundError | Could not find the remote host |
QBluetoothSocket::ServiceNotFoundError | QAbstractSocket::SocketAddressNotAvailableError | Could not find the service UUID on remote host |
QBluetoothSocket::NetworkError | QAbstractSocket::NetworkError | Attempt to read or write from socket returned an error |
This enum describes the state of the Bluetooth socket.
Constant | Value | Description |
---|---|---|
QBluetoothSocket::UnconnectedState | QAbstractSocket::UnconnectedState | Socket is not connected. |
QBluetoothSocket::ServiceLookupState | QAbstractSocket::HostLookupState | Socket is querying connection parameters. |
QBluetoothSocket::ConnectingState | QAbstractSocket::ConnectingState | Socket is attempting to connect to a device. |
QBluetoothSocket::ConnectedState | QAbstractSocket::ConnectedState | Socket is connected to a device. |
QBluetoothSocket::BoundState | QAbstractSocket::BoundState | Socket is bound to a local address and port. |
QBluetoothSocket::ClosingState | QAbstractSocket::ClosingState | Socket is connected and will be closed once all pending data is written to the socket. |
QBluetoothSocket::ListeningState | QAbstractSocket::ListeningState | Socket is listening for incoming connections. |
This enum describes the Bluetooth socket type.
Constant | Value | Description |
---|---|---|
QBluetoothSocket::UnknownSocketType | -1 | Unknown socket type. |
QBluetoothSocket::L2capSocket | 0 | L2CAP socket. |
QBluetoothSocket::RfcommSocket | 1 | RFCOMM socket. |
Constructs a Bluetooth socket of socketType type, with parent.
Constructs a Bluetooth socket with parent.
Destroys the Bluetooth socket.
Aborts the current connection and resets the socket. Unlike disconnectFromService(), this function immediately closes the socket, discarding any pending data in the write buffer.
See also disconnectFromService() and close().
Reimplemented from QIODevice::bytesAvailable().
Returns the number of incoming bytes that are waiting to be read.
See also bytesToWrite() and read().
Reimplemented from QIODevice::bytesToWrite().
Returns the number of bytes that are waiting to be written. The bytes are written when control goes back to the event loop.
Reimplemented from QIODevice::canReadLine().
Returns true if you can read at least one line from the device
Reimplemented from QIODevice::close().
Disconnects the socket's connection with the device.
Attempts to connect to the service described by service.
The socket is opened in the given openMode.
The socket first enters ConnectingState and attempts to connect to the device providing service. If a connection is established, QBluetoothSocket enters ConnectedState and emits connected().
At any point, the socket can emit error() to siganl that an error occurred.
See also state() and disconnectFromService().
Attempts to make a connection to the service identified by uuid on the device with address address.
The socket is opened in the given openMode.
The socket first enters the ServiceLookupState and queries the connection parameters for uuid. If the service parameters are successfully retrieved the socket enters ConnectingState, and attempts to connect to address. If a connection is established, QBluetoothSocket enters Connected State and emits connected().
At any point, the socket can emit error() to signal that an error occurred.
See also state() and disconnectFromService().
Attempts to make a connection with address on the given port.
The socket is opened in the given openMode.
The socket first enters ConnectingState, and attempts to connect to address. If a connection is established, QBluetoothSocket enters ConnectedState and emits connected().
At any point, the socket can emit error() to signal that an error occurred.
See also state() and disconnectFromService().
This signal is emitted when a connection is established.
See also QBluetoothSocket::ConnectedState and stateChanged().
Attempts to close the socket. If there is pending data waiting to be written QBluetoothSocket will enter ClosingState and wait until all data has been written. Eventually, it will enter UnconnectedState and emit the disconnected() signal.
See also connectToService().
This signal is emitted when the socket is disconnected.
See also QBluetoothSocket::UnconnectedState and stateChanged().
Start device discovery for service and open the socket with openMode. If the socket is created with a service uuid device address, use service discovery to find the port number to connect to.
Returns the last error.
This signal is emitted when an error occurs.
See also error().
Returns a user displayable text string for the error.
Reimplemented from QIODevice::isSequential().
Returns the address of the local device.
Returns the name of the local device.
Returns the port number of the local socket if available, otherwise returns 0.
Returns the address of the peer device.
Returns the name of the peer device.
Return the port number of the peer socket if available, otherwise returns 0.
Reimplemented from QIODevice::readData().
Set the socket to use socketDescriptor with a type of socketType, which is in state, socketState, and mode, openMode.
Returns true on success
See also socketDescriptor().
Sets the type of error that last occurred to error_.
Sets the socket state to state.
Returns the platform-specific socket descriptor, if available.
See also setSocketDescriptor().
Returns the socket type.
Returns the current state of the socket.
This signal is emitted when the socket state changes to state.
See also connected(), disconnected(), state(), and QBluetoothSocket::SocketState.
Reimplemented from QIODevice::writeData().