Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Classes principales  ·  Annotées  ·  Classes groupées  ·  Modules  ·  Fonctions  · 

QBluetoothSocket Class

The QBluetoothSocket class enables connection to a Bluetooth device running an RFCOMM server. More...

 #include <QBluetoothSocket>

Inherits: QIODevice.

Public Types

flags OpenMode
enum OpenModeFlag { NotOpen, ReadOnly, WriteOnly, ReadWrite, ..., Unbuffered }
enum SocketError { UnknownSocketError, NoSocketError, ConnectionRefusedError, RemoteHostClosedError, ..., NetworkError }
enum SocketState { UnconnectedState, ServiceLookupState, ConnectingState, ConnectedState, ..., ListeningState }
enum SocketType { UnknownSocketType, L2capSocket, RfcommSocket }

Public Functions

QBluetoothSocket(SocketType socketType, QObject * parent = 0)
QBluetoothSocket(QObject * parent = 0)
QIODevice()
QIODevice(QObject * parent)
virtual ~QBluetoothSocket()
virtual ~QIODevice()
void abort()
virtual bool atEnd() const
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
bool getChar(char * c)
bool isOpen() const
bool isReadable() const
virtual bool isSequential() const
bool isTextModeEnabled() const
bool isWritable() const
QBluetoothAddress localAddress() const
QString localName() const
quint16 localPort() const
virtual bool open(OpenMode mode)
OpenMode openMode() const
qint64 peek(char * data, qint64 maxSize)
QByteArray peek(qint64 maxSize)
QBluetoothAddress peerAddress() const
QString peerName() const
quint16 peerPort() const
virtual qint64 pos() const
bool putChar(char c)
qint64 read(char * data, qint64 maxSize)
QByteArray read(qint64 maxSize)
QByteArray readAll()
qint64 readLine(char * data, qint64 maxSize)
QByteArray readLine(qint64 maxSize = 0)
virtual bool reset()
virtual bool seek(qint64 pos)
bool setSocketDescriptor(int socketDescriptor, SocketType socketType, SocketState socketState = ConnectedState, OpenMode openMode = ReadWrite)
void setTextModeEnabled(bool enabled)
virtual qint64 size() const
int socketDescriptor() const
SocketType socketType() const
SocketState state() const
void ungetChar(char c)
virtual bool waitForBytesWritten(int msecs)
virtual bool waitForReadyRead(int msecs)
qint64 write(const char * data, qint64 maxSize)
qint64 write(const char * data)
qint64 write(const QByteArray & byteArray)

Reimplemented Public Functions

virtual qint64 bytesAvailable() const
virtual qint64 bytesToWrite() const
virtual bool canReadLine() const
virtual void close()
virtual bool isSequential() const
  • 31 public functions inherited from QObject

Signals

void aboutToClose()
void bytesWritten(qint64 bytes)
void connected()
void disconnected()
void error(QBluetoothSocket::SocketError error)
void readChannelFinished()
void readyRead()
void stateChanged(QBluetoothSocket::SocketState state)

Protected Functions

void doDeviceDiscovery(const QBluetoothServiceInfo & service, OpenMode openMode)
virtual qint64 readData(char * data, qint64 maxSize) = 0
virtual qint64 readLineData(char * data, qint64 maxSize)
void setErrorString(const QString & str)
void setOpenMode(OpenMode openMode)
void setSocketError(SocketError error_)
void setSocketState(SocketState state)
virtual qint64 writeData(const char * data, qint64 maxSize) = 0

Reimplemented Protected Functions

virtual qint64 readData(char * data, qint64 maxSize)
virtual qint64 writeData(const char * data, qint64 maxSize)
  • 9 protected functions inherited from QObject

Additional Inherited Members

  • 1 property inherited from QObject
  • 1 public slot inherited from QObject
  • 11 static public members inherited from QObject

Detailed Description

The 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

enum QBluetoothSocket::SocketError

This enum describes Bluetooth socket error types.

ConstantValueDescription
QBluetoothSocket::UnknownSocketErrorQAbstractSocket::UnknownSocketErrorAn unknown error has occurred.
QBluetoothSocket::NoSocketError-2No error. Used for testing.
QBluetoothSocket::ConnectionRefusedErrorQAbstractSocket::ConnectionRefusedErrorConnection refused or device not available.
QBluetoothSocket::RemoteHostClosedErrorQAbstractSocket::RemoteHostClosedErrorThe remote host closed the socket
QBluetoothSocket::HostNotFoundErrorQAbstractSocket::HostNotFoundErrorCould not find the remote host
QBluetoothSocket::ServiceNotFoundErrorQAbstractSocket::SocketAddressNotAvailableErrorCould not find the service UUID on remote host
QBluetoothSocket::NetworkErrorQAbstractSocket::NetworkErrorAttempt to read or write from socket returned an error

enum QBluetoothSocket::SocketState

This enum describes the state of the Bluetooth socket.

ConstantValueDescription
QBluetoothSocket::UnconnectedStateQAbstractSocket::UnconnectedStateSocket is not connected.
QBluetoothSocket::ServiceLookupStateQAbstractSocket::HostLookupStateSocket is querying connection parameters.
QBluetoothSocket::ConnectingStateQAbstractSocket::ConnectingStateSocket is attempting to connect to a device.
QBluetoothSocket::ConnectedStateQAbstractSocket::ConnectedStateSocket is connected to a device.
QBluetoothSocket::BoundStateQAbstractSocket::BoundStateSocket is bound to a local address and port.
QBluetoothSocket::ClosingStateQAbstractSocket::ClosingStateSocket is connected and will be closed once all pending data is written to the socket.
QBluetoothSocket::ListeningStateQAbstractSocket::ListeningStateSocket is listening for incoming connections.

enum QBluetoothSocket::SocketType

This enum describes the Bluetooth socket type.

ConstantValueDescription
QBluetoothSocket::UnknownSocketType-1Unknown socket type.
QBluetoothSocket::L2capSocket0L2CAP socket.
QBluetoothSocket::RfcommSocket1RFCOMM socket.

Member Function Documentation

QBluetoothSocket::QBluetoothSocket(SocketType socketType, QObject * parent = 0)

Constructs a Bluetooth socket of socketType type, with parent.

QBluetoothSocket::QBluetoothSocket(QObject * parent = 0)

Constructs a Bluetooth socket with parent.

QBluetoothSocket::~QBluetoothSocket() [virtual]

Destroys the Bluetooth socket.

void QBluetoothSocket::abort()

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().

qint64 QBluetoothSocket::bytesAvailable() const [virtual]

Reimplemented from QIODevice::bytesAvailable().

Returns the number of incoming bytes that are waiting to be read.

See also bytesToWrite() and read().

qint64 QBluetoothSocket::bytesToWrite() const [virtual]

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.

bool QBluetoothSocket::canReadLine() const [virtual]

Reimplemented from QIODevice::canReadLine().

Returns true if you can read at least one line from the device

void QBluetoothSocket::close() [virtual]

Reimplemented from QIODevice::close().

Disconnects the socket's connection with the device.

void QBluetoothSocket::connectToService(const QBluetoothServiceInfo & service, OpenMode openMode = ReadWrite)

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().

void QBluetoothSocket::connectToService(const QBluetoothAddress & address, const QBluetoothUuid & uuid, OpenMode openMode = ReadWrite)

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().

void QBluetoothSocket::connectToService(const QBluetoothAddress & address, quint16 port, OpenMode openMode = ReadWrite)

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().

void QBluetoothSocket::connected() [signal]

This signal is emitted when a connection is established.

See also QBluetoothSocket::ConnectedState and stateChanged().

void QBluetoothSocket::disconnectFromService()

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().

void QBluetoothSocket::disconnected() [signal]

This signal is emitted when the socket is disconnected.

See also QBluetoothSocket::UnconnectedState and stateChanged().

void QBluetoothSocket::doDeviceDiscovery(const QBluetoothServiceInfo & service, OpenMode openMode) [protected]

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.

SocketError QBluetoothSocket::error() const

Returns the last error.

void QBluetoothSocket::error(QBluetoothSocket::SocketError error) [signal]

This signal is emitted when an error occurs.

See also error().

QString QBluetoothSocket::errorString() const

Returns a user displayable text string for the error.

bool QBluetoothSocket::isSequential() const [virtual]

Reimplemented from QIODevice::isSequential().

QBluetoothAddress QBluetoothSocket::localAddress() const

Returns the address of the local device.

QString QBluetoothSocket::localName() const

Returns the name of the local device.

quint16 QBluetoothSocket::localPort() const

Returns the port number of the local socket if available, otherwise returns 0.

QBluetoothAddress QBluetoothSocket::peerAddress() const

Returns the address of the peer device.

QString QBluetoothSocket::peerName() const

Returns the name of the peer device.

quint16 QBluetoothSocket::peerPort() const

Return the port number of the peer socket if available, otherwise returns 0.

qint64 QBluetoothSocket::readData(char * data, qint64 maxSize) [virtual protected]

Reimplemented from QIODevice::readData().

bool QBluetoothSocket::setSocketDescriptor(int socketDescriptor, SocketType socketType, SocketState socketState = ConnectedState, OpenMode openMode = ReadWrite)

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().

void QBluetoothSocket::setSocketError(SocketError error_) [protected]

Sets the type of error that last occurred to error_.

void QBluetoothSocket::setSocketState(SocketState state) [protected]

Sets the socket state to state.

int QBluetoothSocket::socketDescriptor() const

Returns the platform-specific socket descriptor, if available.

See also setSocketDescriptor().

SocketType QBluetoothSocket::socketType() const

Returns the socket type.

SocketState QBluetoothSocket::state() const

Returns the current state of the socket.

void QBluetoothSocket::stateChanged(QBluetoothSocket::SocketState state) [signal]

This signal is emitted when the socket state changes to state.

See also connected(), disconnected(), state(), and QBluetoothSocket::SocketState.

qint64 QBluetoothSocket::writeData(const char * data, qint64 maxSize) [virtual protected]

Reimplemented from QIODevice::writeData().

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 5.0-snapshot
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web