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  ·  Toutes les fonctions  ·  Vues d'ensemble  · 

QBluetoothAbstractSocket Class Reference
[QtBluetoothModule]

The QBluetoothAbstractSocket class represents an abstract Bluetooth client socket. More...

    #include <QBluetoothAbstractSocket>

Inherits QIODevice.

Inherited by QBluetoothL2CapDatagramSocket, QBluetoothL2CapSocket, QBluetoothRfcommSocket, and QBluetoothScoSocket.

Public Types

  • enum SocketError { NoError, AccessError, ResourceError, BindError, ..., UnknownError }
  • enum SocketState { UnconnectedState, ConnectingState, ConnectedState, BoundState, ClosingState }

Public Functions

  • 32 public functions inherited from QIODevice
  • 29 public functions inherited from QObject

Signals

Additional Inherited Members

  • 1 property inherited from QObject
  • 1 public slot inherited from QObject
  • 1 public type inherited from QObject
  • 4 static public members inherited from QObject
  • 5 protected functions inherited from QIODevice
  • 7 protected functions inherited from QObject
  • 2 protected variables inherited from QObject

Detailed Description

The QBluetoothAbstractSocket class represents an abstract Bluetooth client socket.

QBluetoothAbstractSocket is a common base class used by all Bluetooth sockets. This class implements functionality common to all socket types.

Clients that need to interact with RFCOMM based services should use the QBluetoothRfcommSocket class. For interacting with L2CAP based services, use the QBluetoothL2CapSocket class. Headset and Handsfree profile implementations might need to use the QBluetoothScoSocket class.

At any time, the QBluetoothAbstractSocket has a state (returned by state()). Upon creation, the initial state is QBluetoothAbstractSocket::UnconnectedState.

After calling connect(), the socket enters the QBluetoothAbstractSocket::ConnectingState. If connection is established, the socket enters QBluetoothAbstractSocket::ConnectedState and emits connected().

If an error occurs at any time, the error() signal is emitted. Whenever the state changes, stateChanged() is emitted. For convenience, isValid() returns true if the socket is ready for reading and writing.

Read or write data to/from the socket by calling read() or write(), or use the convenience functions readLine() and readAll(). QBluetoothAbstractSocket also inherits getChar(), putChar(), and ungetChar() from QIODevice, which work on single bytes. For every chunk of data that has been written to the socket, the bytesWritten() signal is emitted.

The readyRead() signal is emitted every time a new chunk of data has arrived. bytesAvailable() then returns the number of bytes that are available for reading. Typically, you would connect the readyRead() signal to a slot and read all available data there. If you don't read all the data at once, the remaining data will still be available later, and any new incoming data will be appended to QBluetoothAbstractSocket's internal read buffer. To limit the size of the read buffer, call setReadBufferSize().

To close the socket, call disconnect(). Once disconnect() is called, QBluetoothAbstractSocket enters the QBluetoothAbstractSocket::ClosingState and emits the stateChanged() signal. After all pending data has been written to the socket, QBluetoothAbstractSocket actually closes the socket, enters the QBluetoothAbstractSocket::ClosedState, and emits disconnected(). If no data is pending when disconnect() is called, the connection is disconnected immediately. If you want to abort a connection immediately, discarding all pending data, call abort() instead.

QBluetoothAbstractSocket provides a set of functions that suspend the calling thread until certain signals are emitted. These functions can be used to implement blocking sockets:

See also QBluetoothRfcommSocket, QBluetoothL2CapSocket, QBluetoothScoSocket, and QBluetoothL2CapDatagramSocket.


Member Type Documentation

enum QBluetoothAbstractSocket::SocketError

Error that last occurred on the rfcomm socket.

ConstantValueDescription
QBluetoothAbstractSocket::NoError0No error has occurred.
QBluetoothAbstractSocket::AccessError1The client has inadequate permissions to access the socket.
QBluetoothAbstractSocket::ResourceError2The kernel has run out of sockets.
QBluetoothAbstractSocket::BindError3The socket could not be bound to a particular address.
QBluetoothAbstractSocket::ConnectionRefused4The remote host has refused a connection.
QBluetoothAbstractSocket::HostDownError5The remote host could not be contacted.
QBluetoothAbstractSocket::NetworkError6A network error has occurred, e.g. device moved out of range.
QBluetoothAbstractSocket::TimeoutError7Operation has timed out.
QBluetoothAbstractSocket::RemoteHostClosedError8Remote host has closed the connection.
QBluetoothAbstractSocket::BusyError9The system is busy.
QBluetoothAbstractSocket::HostUnreachableError10The remote host could not be reached.
QBluetoothAbstractSocket::UnsupportedOperationError11The operation is not supported.
QBluetoothAbstractSocket::AddressInUseError12Address is currently in use.
QBluetoothAbstractSocket::AddressNotAvailableError13Address is not available.
QBluetoothAbstractSocket::UnknownError14Unknown error has occurred.

enum QBluetoothAbstractSocket::SocketState

State of the rfcomm socket.

ConstantValueDescription
QBluetoothAbstractSocket::UnconnectedState0The socket is not connected.
QBluetoothAbstractSocket::ConnectingState1The socket is being connected.
QBluetoothAbstractSocket::ConnectedState2The socket is connected.
QBluetoothAbstractSocket::BoundState3The socket has been bound.
QBluetoothAbstractSocket::ClosingState4The socket is being closed.


Member Function Documentation

QBluetoothAbstractSocket::~QBluetoothAbstractSocket ()

Deconstructs a QBluetoothAbstractSocket. If the socket is in any state other than UnconnectedState, the current connection is aborted.

void QBluetoothAbstractSocket::abort ()

Aborts the current connection and resets the socket. Unlike disconnect(), this function immediately closes the socket, clearing any pending data in the write buffer.

See also disconnect() and close().

qint64 QBluetoothAbstractSocket::bytesAvailable () const   [virtual]

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

Reimplemented from QIODevice.

See also bytesToWrite() and read().

qint64 QBluetoothAbstractSocket::bytesToWrite () const   [virtual]

Returns the number of bytes which are pending to be written.

Reimplemented from QIODevice.

See also bytesAvailable() and write().

bool QBluetoothAbstractSocket::canReadLine () const   [virtual]

Returns true if a line of data can be read from the socket; otherwise returns false.

Reimplemented from QIODevice.

See also readLine().

void QBluetoothAbstractSocket::close ()   [virtual]

Closes the socket. Pending data will not be flushed first. The socket will be immediately closed.

Reimplemented from QIODevice.

See also abort() and disconnect().

void QBluetoothAbstractSocket::connected ()   [signal]

This signal is emitted once the connect() has been called and the rfcomm socket has been successfully connected.

See also connect() and disconnected().

bool QBluetoothAbstractSocket::disconnect ()   [virtual]

Attempts to close the socket. If there is pending data waiting to be written, the socket will enter ClosingState and wait until all data has been written. Eventually it will enter UnconnectedState and emit the disconnected() signal.

Returns true on successful completion of the request; otherwise returns false.

See also close().

void QBluetoothAbstractSocket::disconnected ()   [signal]

This signal is emitted when the socket has been disconnected.

See also connect(), disconnect(), and abort().

SocketError QBluetoothAbstractSocket::error () const

Returns the last error that has occurred.

See also state().

void QBluetoothAbstractSocket::error ( QBluetoothAbstractSocket::SocketError socketError )   [signal]

This is an overloaded member function, provided for convenience.

This signal is emitted after an error occurred. The socketError parameter describes the type of error that has occurred.

See also error() and errorString().

bool QBluetoothAbstractSocket::flush ()   [virtual]

This function writes as much as possible from the internal write buffer to the underlying network socket, without blocking. If any data was written, this function returns true; otherwise false is returned.

See also write() and waitForBytesWritten().

qint64 QBluetoothAbstractSocket::readBufferSize () const

Returns the size of the internal read buffer. This limits the amount of data that the client can receive before you call read() or readAll().

A read buffer size of 0 (the default) means that the buffer has no size limit, ensuring that no data is lost.

See also setReadBufferSize() and read().

void QBluetoothAbstractSocket::setReadBufferSize ( qint64 size )

Sets the capacity of QBluetoothAbstractSocket's internal read buffer to be size bytes. If size is 0 the buffer has unlimited capacity. This is the default.

See also readBufferSize().

bool QBluetoothAbstractSocket::setSocketDescriptor ( int socketDescriptor, QBluetoothAbstractSocket::SocketState state, QIODevice::OpenMode openMode = QIODevice::ReadWrite )

Initializes the QBluetoothAbstractSocket with the native descriptor socketDescriptor. The socket is put into the state and opened in openMode.

Returns true on successful completion of the request; otherwise returns false.

See also socketDescriptor().

int QBluetoothAbstractSocket::socketDescriptor () const

Returns the socket descriptor for the socket if the socket is currently active (e.g. not in UnconnectedState). Otherwise returns -1.

See also setSocketDescriptor() and state().

SocketState QBluetoothAbstractSocket::state () const

Returns the state of the socket.

See also error().

void QBluetoothAbstractSocket::stateChanged ( QBluetoothAbstractSocket::SocketState socketState )   [signal]

This signal is emitted when the state of the socket has changed. The socketState parameter holds the new state.

See also state().

bool QBluetoothAbstractSocket::waitForConnected ( int msecs = 30000 )

Waits until the socket is connected, up to msecs milliseconds. If the connection has been established, this function returns true; otherwise returns false. In the case where it returns false, you can call error() to determine the cause of the error.

This is a blocking function call. Its use is not advised in a single-threaded GUI application, since the whole application will stop responding until the function returns. waitForNewConnected() is mostly useful when there is no event loop available.

See also connect() and connected().

bool QBluetoothAbstractSocket::waitForDisconnected ( int msecs = 30000 )

Waits until the socket is disconnected, up to msecs milliseconds. If the connection has been terminated, this function returns true; otherwise returns false. In the case where it returns false, you can call error() to determine the cause of the error.

This is a blocking function call. Its use is not advised in a single-threaded GUI application, since the whole application will stop responding until the function returns. waitForDisconnected() is mostly useful when there is no event loop available.

See also disconnect(), close(), and disconnected().

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 102
  2. Pourquoi les programmeurs sont-ils moins payés que les gestionnaires de programmes ? Manquent-ils de pouvoir de négociation ? 53
  3. «Le projet de loi des droits du développeur» : quelles conditions doivent remplir les entreprises pour que le développeur puisse réussir ? 74
  4. Les développeurs détestent-ils les antivirus ? Un programmeur manifeste sa haine envers ces solutions de sécurité 28
  5. Qt Commercial : Digia organise un webinar gratuit le 27 mars sur la conception d'interfaces utilisateur et d'applications avec le framework 0
  6. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
  7. 2017 : un quinquennat pour une nouvelle version du C++ ? Possible, selon Herb Sutter 11
Page suivante
  1. Linus Torvalds : le "C++ est un langage horrible", en justifiant le choix du C pour le système de gestion de version Git 100
  2. Comment prendre en compte l'utilisateur dans vos applications ? Pour un développeur, « 90 % des utilisateurs sont des idiots » 229
  3. Quel est LE livre que tout développeur doit lire absolument ? Celui qui vous a le plus marqué et inspiré 96
  4. Apple cède et s'engage à payer des droits à Nokia, le conflit des brevets entre les deux firmes s'achève 158
  5. Nokia porte à nouveau plainte contre Apple pour violation de sept nouveaux brevets 158
  6. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 102
  7. Quel est le code dont vous êtes le plus fier ? Pourquoi l'avez-vous écrit ? Et pourquoi vous a-t-il donné autant de satisfaction ? 83
Page suivante

Le Qt Quarterly au hasard

Logo

Écrire des fichiers ODF avec Qt

Qt Quarterly est la revue trimestrielle proposée par Nokia et à destination des développeurs Qt. Ces articles d'une grande qualité technique sont rédigés par des experts Qt. Lire l'article.

Communauté

Ressources

Liens utiles

Contact

  • Vous souhaitez rejoindre la rédaction ou proposer un tutoriel, une traduction, une question... ? Postez dans le forum Contribuez ou contactez-nous par MP ou par email (voir en bas de page).

Qt dans le magazine

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 qtextended4.4
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