Home · All Namespaces · All Classes · Grouped Classes · Modules · Functions codeless banner

QBluetoothAbstractServer Class Reference
[QtBluetoothModule]

The QBluetoothAbstractServer class represents an abstract Bluetooth server socket. More...

    #include <QBluetoothAbstractServer>

Inherits QObject.

Inherited by QBluetoothL2CapServer, QBluetoothRfcommServer, and QBluetoothScoServer.

Public Functions

Signals

Additional Inherited Members


Detailed Description

The QBluetoothAbstractServer class represents an abstract Bluetooth server socket.

This class is a common base class for all Bluetooth server socket implementations and makes it possible to accept incoming Bluetooth connections. The users should not use this class directly, instead they should use concrete implementations.

The subclasses will implement a listen() implementation in order to create a listening socket for each particular Bluetooth socket type. In particular, QBluetoothL2CapServer, QBluetoothRfcommServer, and QBluetoothScoServer will create L2CAP, RFCOMM and SCO sockets respectively.

Services that provide RFCOMM based profiles should use the QBluetoothRfcommServer class. L2CAP based services should use the QBluetoothL2CapServer class. Headset and Handsfree profile implementations will require the use of QBluetoothScoServer class.

The typical use of this class is to call the listen() implementation in the subclass, and then hook onto the newConnection() signal to get an indication of an incoming connection. The newConnection() signal is emitted each time a client has connected to the server. Call nextPendingConnection() to accept the pending connection as a connected QBluetoothAbstractSocket. The actual socket type depends on the type of the server. E.g. the QBluetoothRfcommServer socket will return QBluetoothRfcommSocket type sockets.

If an error occurs, serverError() returns the type of error that has occurred.

Calling close() makes the QBluetoothAbstractServer stop listening for incoming connections and deletes all pending connections.

See also QBluetoothAbstractSocket.


Member Function Documentation

QBluetoothAbstractServer::~QBluetoothAbstractServer ()

Destroys the server.

void QBluetoothAbstractServer::close ()   [virtual]

Closes the server. The server will no longer listen for incoming connections and all pending connections will be closed.

See also isListening() and socketDescriptor().

QString QBluetoothAbstractServer::errorString () const

Returns a human-readable description of the last device error that occurred.

See also serverError().

bool QBluetoothAbstractServer::hasPendingConnections () const

Returns true if the server has a pending connection(s); otherwise returns false.

See also nextPendingConnection() and setMaxPendingConnections().

bool QBluetoothAbstractServer::isListening () const

Returns true if the server is currently listening for remote connections, and false otherwise.

See also close() and socketDescriptor().

int QBluetoothAbstractServer::maxPendingConnections () const

Returns the maximum number of pending accepted connections. The default is 1.

See also setMaxPendingConnections() and hasPendingConnections().

void QBluetoothAbstractServer::newConnection ()   [signal]

This signal is emitted every time a new connection is available. Call nextPendingConnection() in order to accept the connection.

See also hasPendingConnections() and nextPendingConnection().

QBluetoothAbstractSocket * QBluetoothAbstractServer::nextPendingConnection ()

Returns the next pending connection as a connected QBluetoothAbstractSocket object. The function returns a pointer to a QBluetoothAbstractSocket in QBluetoothAbstractSocket::ConnectedState that you can use for communicating with the client.

The type of the socket returned will be based on the server socket type used. You will need to use qobject_cast to convert the result into the concrete socket type required.

    QBluetoothAbstractSocket *sock = server->nextPendingConnection();
    if (sock) {
        QBluetoothRfcommSocket *rfcomm =
            qobject_cast<QBluetoothRfcommSocket *>(sock);
        if (rfcomm) {
            // use RFCOMM socket
        }
    }

The socket is created as a child of the server, which means that it is automatically deleted when the QBluetoothAbstractServer object is destroyed. It is still a good idea to delete the object explicitly when you are done with it, to avoid wasting memory.

A NULL pointer is returned if this function is called when there are no pending connections.

See also hasPendingConnections().

QBluetoothAbstractSocket::SocketError QBluetoothAbstractServer::serverError () const

Returns the last error that has occurred.

See also errorString().

void QBluetoothAbstractServer::setMaxPendingConnections ( int numConnections )

Sets the maximum number of pending accepted connections to numConnections. QBluetoothAbstractServer will accept no more than numConnections incoming connections before nextPendingConnection() is called. By default, the limit is 1 pending connection.

See also maxPendingConnections() and hasPendingConnections().

int QBluetoothAbstractServer::socketDescriptor () const

Returns the socket descriptor the server is currently listening on. If the server is not listening, then -1 is returned.

See also isListening().

bool QBluetoothAbstractServer::waitForNewConnection ( int msecs = 0, bool * timedOut = 0 )

Waits for at most msecs milliseconds or until an incoming connection is available. Returns true if a connection is available; otherwise returns false. If the operation timed out and timedOut is not 0, *timedOut will be set to true.

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. waitForNewConnection() is mostly useful when there is no event loop available.

The non-blocking alternative is to connect to the newConnection() signal.

See also hasPendingConnections() and nextPendingConnection().


Copyright © 2009 Trolltech Trademarks
Qt Extended 4.4.3