QBluetoothZero  2.0
QBtSerialPortClient Class Reference

#include <QBtSerialPortClient.h>

List of all members.

Public Types

enum  ErrorCode {
  ErrorAlreadyInUse, ErrorNotSupported, ErrorUnavailable, ErrorOpeningConnection,
  ErrorAlreadyConnected, ErrorUndefinedError, ErrorUnableToInitializePort, ErrorNoDeviceSelected,
  ErrorNoServiceSelected, ErrorConnectionError, ErrorConnectionTimeout, ErrorOnDisconnecting

Public Slots

void connect (const QBtDevice &remoteDevice, const QBtService &remoteService)
void disconnect ()
void sendData (const QString &data)
void sendData (const QByteArray &data)


void disconnectedFromServer ()
void connectionResetByPeer ()
void connectedToServer ()
void dataSent ()
void dataReceived (const QString &data)
void dataReceived (const QByteArray &data)
void error (QBtSerialPortClient::ErrorCode error)

Public Member Functions

 QBtSerialPortClient (QObject *parent)
 ~QBtSerialPortClient ()
bool isConnected ()


class QBtSerialPortClientPrivate

Detailed Description

Class that provides the mechanism to connect to a bluetooth serial port server and communicate.

Calling connect(const QBtDevice&, const QBtService&) user specifies on which device to connect(on which serial port server) and on which bluetooth service. The QBtDevice instance of the server can be aquired using QBtDeviceDiscoverer or user can create his own instance and set at least the QBtAddress field. Also the QBtService can be aquired using QBtServiceDiscoverer targeting the beforementioned device.

On successfull connection, connectedToServer() singal is emitted and user is able to sendData(const QString&) to the server. If successfull then dataSend() signal is emitted.

If data is recieved from the server, dataReceived(const QString) signal is emitted containing the bytes recieved. At this point user must be carefull to read the data recieved using the same encoding as the sender (in this case serial port server). QString contains all the necessary functions for character encoding that is why is QString is used instead of QByteArray.

When connection is no longer needed, disconnect() can be called. disconnectedFromServer() is then emitted.

In case of error error(QBtSerialPortClient::ErrorCode) signal is emitted.

Member Enumeration Documentation


Constructor & Destructor Documentation

QBtSerialPortClient::QBtSerialPortClient ( QObject *  parent)

A Serial port client. According to the bluetooth specification, up to 7 instances of this class can be connected simultaneously to other servers.

QBtSerialPortClient::~QBtSerialPortClient ( )


If isConnected() then disconnect() is called.

Member Function Documentation

void QBtSerialPortClient::connect ( const QBtDevice remoteDevice,
const QBtService remoteService 
) [slot]

connect() RemoteDevice must contain at least the device address. and remoteService at least a class ID (in case of SerialPort port field is also needed). The remoteService info can be acquired by QBtServiceDiscoverer.

void QBtSerialPortClient::connectedToServer ( ) [signal]

Emitted when successfully connected to the remote server.

void QBtSerialPortClient::connectionResetByPeer ( ) [signal]

Emitted when the server initiated a disconnection.

void QBtSerialPortClient::dataReceived ( const QString &  data) [signal]

Emitted as feedback when data are received successfully.

void QBtSerialPortClient::dataReceived ( const QByteArray &  data) [signal]

Emitted the instance the dataReceived(const QString&) signal is emitted. User decides which format wants to read.

void QBtSerialPortClient::dataSent ( ) [signal]

Emitted when after sendData(QString) is called, if the data is send successfully.

void QBtSerialPortClient::disconnect ( ) [slot]

disconnect() Disconnects from the remote server if previously succusfully connected.

void QBtSerialPortClient::disconnectedFromServer ( ) [signal]

Emitted when successfully disconnected from the remote server (initiated from client).

void QBtSerialPortClient::error ( QBtSerialPortClient::ErrorCode  error) [signal]

Emitted in case of error.

bool QBtSerialPortClient::isConnected ( )


Returns whether or not the client is connected to a remote server.

void QBtSerialPortClient::sendData ( const QString &  data) [slot]

sendData() Send a string to the server. If text is transmitted, it is up to the user to decide which text encoding to use. Upon succesfull transmittion, dataSent() signal is emitted.

void QBtSerialPortClient::sendData ( const QByteArray &  data) [slot]

Send a array of bytes to the server, as is. Upon succesfull transmittion, dataSent() signal is emitted.

Friends And Related Function Documentation

friend class QBtSerialPortClientPrivate [friend]

The documentation for this class was generated from the following file: