Home · All Namespaces · All Classes · Grouped Classes · Modules · Functions |
The QBluetoothRfcommSerialPort class represents a RFCOMM serial port device. More...
#include <QBluetoothRfcommSerialPort>
Inherits QObject.
The QBluetoothRfcommSerialPort class represents a RFCOMM serial port device.
This class enables conversion of RFCOMM sockets into serial tty devices. The class can be used in two major ways, by adapting an existing connected RFCOMM socket or by using the connect() function to establish a client connection to a remote device and adapt the resulting connection to a tty device.
The resulting tty device can be used by other applications like a regular serial tty device.
// Adapt a connected RFCOMM socket into a serial tty device if (rfcommSocket->state() != QBluetoothRfcommSocket::ConnectedState) { // Bail out return; } QBluetoothRfcommSerialPort *serial = new QBluetoothRfcommSerialPort(rfcommSocket); if (serial->id() == -1) { // Error creating serial port return; } rfcommSocket->close(); // Use serial port openSerialPort(serial->device());
See also QBluetoothRfcommSocket and QSerialIODevice.
Defines errors that could occur in QBluetoothRfcommSerialPort
Constant | Value | Description |
---|---|---|
QBluetoothRfcommSerialPort::NoError | 0 | No error has occurred. |
QBluetoothRfcommSerialPort::SocketNotConnected | 1 | The given socket is not connected. |
QBluetoothRfcommSerialPort::ConnectionFailed | 2 | Could not connect to the remote device. |
QBluetoothRfcommSerialPort::ConnectionCancelled | 3 | Connection has been cancelled. |
QBluetoothRfcommSerialPort::CreationError | 4 | Could not create the serial port device. |
Defines flags that alter the behavior of the QBluetoothRfcommSerialPort
Constant | Value | Description |
---|---|---|
QBluetoothRfcommSerialPort::KeepAlive | 0x01 | Deleting the serial port object will not necessarily shut down the serial port. The serial port will be kept open until all open handles (file descriptors) to the serial port are closed. You can use the release() method to forcibly delete a serial port. |
The Flags type is a typedef for QFlags<Flag>. It stores an OR combination of Flag values.
Constructs a new RFCOMM serial port object. The parent is passed to the QObject constructor.
Converts a connected RFCOMM socket to an RFCOMM serial port.
This constructor is useful in situations where you already have a connected RFCOMM socket and wish to convert it to a serial port. This is true of connections returned by QBluetoothRfcommServer::nextPendingConnection() or RFCOMM socket connections which require non-blocking connections.
Note: The caller should call QBluetoothRfcommSocket::close() on socket immediately after calling this constructor. Before the created QBluetoothRfcommSerialPort device can be used, the socket should be closed. The deviceFlags parameter holds the optional flags that modify the serial port behavior.
In case the device could not be created or an error occurred, the id() method will return -1. The caller should check the return value of id() before using the serial port device.
See also id().
Destroys a Bluetooth serial port object. If the instance is managing a serial port, disconnect() will be called first.
This method tries to establish a connection to the remote device with address remote on channel. The local device is given by local. This method will return true if the request could be started, and false otherwise. The connected() signal will be sent once the operation completes.
You can cancel the connection process at any time by calling disconnect(). If the process is cancelled, the error() signal will be sent with the QBluetoothRfcommSerialPort::ConnectionCancelled error set.
See also error() and connected().
This signal is emitted whenever the RFCOMM serial port is connected. The device parameter holds the device name of the created serial port.
See also connect().
Returns the RFCOMM tty device which is being managed by the current instance of this class. If the instance is not managing a device, an empty string is returned.
See also id().
Returns true if able to disconnects the serial port; otherwise returns false. The underlying device will be removed unless the QBluetoothRfcommSerialPort::KeepAlive flag is set. The disconnected() signal will be sent once the disconnection is complete.
See also disconnected().
This signal is emitted whenever the RFCOMM serial port is disconnected.
See also disconnect().
Returns the last error that has occurred.
See also errorString().
This is an overloaded member function, provided for convenience.
This signal is emitted whenever an error occurs. The err parameter holds the error that has occurred.
See also connect().
Returns the human readable form of the last error that has occurred.
See also error().
Returns the flags that the serial port has been opened with.
Returns the device id of the associated RFCOMM device. If no device is found, returns -1. The device id is usually in the range of 0-31.
See also device().
Returns a list of all RFCOMM device bindings.
See also releaseDevice().
This is an overloaded member function, provided for convenience.
Returns a list of all RFCOMM devices for a particular Bluetooth adapter given by local.
See also releaseDevice().
Returns the address of the local device. If the socket is not currently connected, returns QBluetoothAddress::invalid.
See also remoteAddress().
Returns true if able to release the RFCOMM device with id; otherwise returns false.
See also listDevices().
Returns the address of the remote device. If the socket is not currently connected, returns QBluetoothAddress::invalid.
See also localAddress() and remoteChannel().
Returns the RFCOMM channel of the remote device. If the socket is not currently connected, returns -1.
See also remoteAddress().
Copyright © 2009 Nokia | Trademarks | Qt Extended 4.4.3 |