QBluetoothSocket
Since: 1.2
#include <QtConnectivity/QBluetoothSocket>
More information will be added here shortly. For now, you'll find more extensive information about this class in the Qt reference for QBluetoothSocket
The QBluetoothSocket class provides a Bluetooth socket.
QBluetoothSocket supports two socket types, {QBluetoothSocket::L2capSocket}{L2CAP} and {QBluetoothSocket::RfcommSocket}{RFCOMM}.
{QBluetoothSocket::L2capSocket}{L2CAP} is a low level datagram-oriented Bluetooth socket.
{QBluetoothSocket::RfcommSocket}{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.
Overview
Inheritance
QIODevice | ||
QBluetoothSocket |
Public Types Index
enum SocketErrorNoSocketError -2, UnknownSocketError QAbstractSocket::UnknownSocketError, ConnectionRefusedError QAbstractSocket::ConnectionRefusedError, RemoteHostClosedError QAbstractSocket::RemoteHostClosedError, HostNotFoundError QAbstractSocket::HostNotFoundError, ServiceNotFoundError QAbstractSocket::SocketAddressNotAvailableError, NetworkError QAbstractSocket::NetworkError | |
enum SocketStateUnconnectedState QAbstractSocket::UnconnectedState, ServiceLookupState QAbstractSocket::HostLookupState, ConnectingState QAbstractSocket::ConnectingState, ConnectedState QAbstractSocket::ConnectedState, BoundState QAbstractSocket::BoundState, ClosingState QAbstractSocket::ClosingState, ListeningState QAbstractSocket::ListeningState | |
enum SocketType | |
enum OpenModeFlagNotOpen 0x0000, ReadOnly 0x0001, WriteOnly 0x0002, ReadWrite ReadOnly | WriteOnly, Append 0x0004, Truncate 0x0008, Text 0x0010, Unbuffered 0x0020 |
Protected Attributes Index
QBluetoothSocketPrivate * | d_ptr |
Public Functions Index
QBluetoothSocket (SocketType socketType, QObject *parent=0) | |
QBluetoothSocket (QObject *parent=0) | |
virtual | ~QBluetoothSocket () |
void | abort () |
virtual qint64 | bytesAvailable () const |
virtual qint64 | bytesToWrite () const |
virtual bool | canReadLine () const |
virtual void | close () |
void | connectToService (const QBluetoothServiceInfo &service, OpenMode openMode=ReadWrite) |
void | connectToService (const QBluetoothAddress &address, const QBluetoothUuid &uuid, OpenMode openMode=ReadWrite) |
void | connectToService (const QBluetoothAddress &address, quint16 port, OpenMode openMode=ReadWrite) |
void | disconnectFromService () |
SocketError | error () const |
QString | errorString () const |
virtual bool | isSequential () const |
QBluetoothAddress | localAddress () const |
QString | localName () const |
quint16 | localPort () const |
QBluetoothAddress | peerAddress () const |
QString | peerName () const |
quint16 | peerPort () const |
bool | setSocketDescriptor (int socketDescriptor, SocketType socketType, SocketState socketState=ConnectedState, OpenMode openMode=ReadWrite) |
int | socketDescriptor () const |
SocketType | socketType () const |
SocketState | state () const |
virtual bool | atEnd () const ![]() |
bool | getChar (char *c)![]() |
bool | isOpen () const ![]() |
bool | isReadable () const ![]() |
bool | isTextModeEnabled () const ![]() |
bool | isWritable () const ![]() |
virtual bool | open (OpenMode mode)![]() |
OpenMode | openMode () const ![]() |
qint64 | peek (char *data, qint64 maxlen)![]() |
QByteArray | peek (qint64 maxlen)![]() |
virtual qint64 | pos () const ![]() |
bool | putChar (char c)![]() |
QIODevice ()![]() | |
QIODevice (QObject *parent)![]() | |
qint64 | read (char *data, qint64 maxlen)![]() |
QByteArray | read (qint64 maxlen)![]() |
QByteArray | readAll ()![]() |
qint64 | readLine (char *data, qint64 maxlen)![]() |
QByteArray | readLine (qint64 maxlen=0)![]() |
virtual bool | reset ()![]() |
virtual bool | seek (qint64 pos)![]() |
void | setTextModeEnabled (bool enabled)![]() |
virtual qint64 | size () const ![]() |
void | ungetChar (char c)![]() |
virtual bool | waitForBytesWritten (int msecs)![]() |
virtual bool | waitForReadyRead (int msecs)![]() |
qint64 | write (const char *data, qint64 len)![]() |
qint64 | write (const char *data)![]() |
qint64 | write (const QByteArray &data)![]() |
Protected Functions Index
void | doDeviceDiscovery (const QBluetoothServiceInfo &service, OpenMode openMode) |
virtual qint64 | readData (char *data, qint64 maxSize) |
void | setSocketError (SocketError error) |
void | setSocketState (SocketState state) |
virtual qint64 | writeData (const char *data, qint64 maxSize) |
QIODevice (QIODevicePrivate &dd, QObject *parent=0)![]() | |
virtual qint64 | readLineData (char *data, qint64 maxlen)![]() |
void | setErrorString (const QString &errorString)![]() |
void | setOpenMode (OpenMode openMode)![]() |
Signals Index
void | connected () |
void | disconnected () |
void | error (QBluetoothSocket::SocketError error) |
void | stateChanged (QBluetoothSocket::SocketState state) |
void | aboutToClose ()![]() |
void | bytesWritten (qint64 bytes)![]() |
void | readChannelFinished ()![]() |
void | readyRead ()![]() |
Public Types
This enum describes Bluetooth socket error types.
UnknownSocketError An unknown error has occurred. NoSocketError No error. Used for testing. ConnectionRefusedError Connection refused or device not available. RemoteHostClosedError The remote host closed the socket HostNotFoundError Could not find the remote host ServiceNotFoundError Could not find the service UUID on remote host NetworkError Attempt to read or write from socket returned an error
- NoSocketError -2
- UnknownSocketError QAbstractSocket::UnknownSocketError
- ConnectionRefusedError QAbstractSocket::ConnectionRefusedError
- RemoteHostClosedError QAbstractSocket::RemoteHostClosedError
- HostNotFoundError QAbstractSocket::HostNotFoundError
- ServiceNotFoundError QAbstractSocket::SocketAddressNotAvailableError
- NetworkError QAbstractSocket::NetworkError
This enum describes the state of the Bluetooth socket.
UnconnectedState Socket is not connected. ServiceLookupState Socket is querying connection parameters. ConnectingState Socket is attempting to connect to a device. ConnectedState Socket is connected to a device. BoundState 242.nmp.nokia.com _IceTransSocketUNIXConnect: Cannot connect to non-local host saisd Socket is bound to a local address and port. ClosingState Socket is connected and will be closed once all pending data is written to the socket. ListeningState Socket is listening for incoming connections.
- UnconnectedState QAbstractSocket::UnconnectedState
- ServiceLookupState QAbstractSocket::HostLookupState
- ConnectingState QAbstractSocket::ConnectingState
- ConnectedState QAbstractSocket::ConnectedState
- BoundState QAbstractSocket::BoundState
- ClosingState QAbstractSocket::ClosingState
- ListeningState QAbstractSocket::ListeningState
This enum describes the Bluetooth socket type.
UnknownSocketType Unknown socket type. L2capSocket L2CAP socket. RfcommSocket RFCOMM socket.
- UnknownSocketType -1
- L2capSocket
- RfcommSocket
- NotOpen 0x0000
- ReadOnly 0x0001
- WriteOnly 0x0002
- ReadWrite ReadOnly | WriteOnly
- Append 0x0004
- Truncate 0x0008
- Text 0x0010
- Unbuffered 0x0020
Protected Attributes
QBluetoothSocketPrivate *
Public Functions
Constructs a Bluetooth socket of socketType type, with parent.
Constructs a Bluetooth socket with parent.
virtual
Destructor.
void
Aborts the current connection and resets the socket.
virtual qint64
Returns the number of incoming bytes that are waiting to be read.
bytesToWrite(), read()
virtual qint64
Returns the number of bytes that are waiting to be written.
The bytes are written when control goes back to the event loop.
virtual bool
Returns true if you can read at least one line from the device.
virtual void
Disconnects the socket's connection with the device.
void
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.
void
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.
void
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.
void
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.
SocketError
Returns the last error.
QString
Returns a user displayable text string for the error.
virtual bool
QBluetoothAddress
Returns the address of the local device.
QString
Returns the name of the local device.
quint16
Returns the port number of the local socket if available; otherwise returns 0.
QBluetoothAddress
Returns the address of the peer device.
QString
Returns the name of the peer device.
quint16
Return the port number of the peer socket if available; otherwise returns 0.
bool
Set the socket to use socketDescriptor with a type of socketType which is in state socketState and mode openMode.
Returns true on success
int
Returns the platform specific socket descriptor, if available.
SocketType
Returns the socket type.
SocketState
Returns the current state of the socket.
virtual bool 
bool 
bool 
bool 
bool 
bool 
virtual bool 
OpenMode 
qint64 
virtual qint64 
bool 
qint64 
qint64 
virtual bool 
virtual bool 
void 
virtual qint64 
void 
virtual bool 
virtual bool 
qint64 
qint64 
qint64 
Protected Functions
void
Start device discovery for service and open the socket with openMode.
If the socket is created with a service uuid device address we must use service discovery to find the port number to connect to.
virtual qint64
void
Sets the type of error that last occurred to error_.
void
Sets the socket state to state.
virtual qint64
virtual qint64 
void 
void 
Signals
void
This signal is emitted when a connection is established.
QBluetoothSocket::ConnectedState, stateChanged()
void
This signal is emitted when the socket is disconnected.
QBluetoothSocket::UnconnectedState, stateChanged()
void
This signal is emitted when the socket state changes to state.
connected(), disconnected(), state(), QBluetoothSocket::SocketState
void 
void 
void 
void 
© 2013 Digia Plc and/or its subsidiaries. Documentation contributions included herein are the copyrights of their respective owners.
The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation.
Documentation sources may be obtained from www.qt-project.org.
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide. All other trademarks are property of their respective owners. Privacy Policy