QBluetoothZero is a 3rd party bluetooth library written on Qt supported on Symbian and Windows. Its architecture is based on S60 Platform: Bluetooth API Developer_s Guide.
The idea is to create a library implementation using Qt (a DLL) of the S60 bluetooth API easy to use by anyone with basic knowledge of Qt.
So the architecture was extracted from S60 bluetooth API, and also source code was used from the following examples:
and the basic guide for combining all these was Using Qt and Symbian C together
NOTE: for more detailed description of the the library_s components please advise the documentation. Documentation can be found in this site QBluetoothZero Documentation.
An application using QBluetoothZero can be found here QuteMessenger - A Qt application using QBluetoothZero
Some code examples from the Nokia Wiki:
Discovering nearby Bluetooth services with the QBluetoothZero library
Discovering Bluetooth devices with the QBluetoothZero library
QBtAddress : that represents the device_s bluetooth address
QBtService : all the necessary information about a bluetooth service
QBtDevice : all the information needed about any remote bluetooth device
QBtLocalDevice : implemented only with static functions through which user can access information of the local device
QBtDeviceDiscoverer: the mechanism of the device discovery
QBtSingleDeviceSelectorUI: a simple widget to select a bluetooth device. Device discovery is initiated when widget is shown. Created for convenience if a user simply wants to select a discovered device to proceed to other operations
QBtServiceDiscoverer: provides the mechanism to inquire a given device for the bluetooth services it supports
QBtServiceAdvertiser: class responsible to advertise a given bluetooth service
QBtObjectExchangeClient : OBEX client, connects to a remote OBEX server to send/retrieve data and files
QBtObjectExchangeServer : OBEX server, waits for clients to connect and ready to serve any OBEX request
QBtSerialPortClient : Serial Port (SP) client, connect to SP server to send/receive raw data through serial port
QBtSerialPortServer : Serial Port server, ready to accept client connections to also send/receive raw data
Follow the appropriate link that corresponds to the platform that you are going to use:
QBtDeviceDiscoverer is used to inquire for bluetooth devices in range.
create new instance
call startDiscovery() to initiate inquiry
call getInquiredDevices() to retrieve the devices found so far or connect to SIGNAL newDeviceFound (QBtDevice) to be reported each time a device is found
QBtDeviceDiscoverer* deviceDiscoverer = new QBtDeviceDiscoverer(this);
connect(deviceDiscoverer , SIGNAL(newDeviceFound (QBtDevice)), this, SLOT(handlerFunction(QBtDevice))); deviceDiscoverer ->startDiscovery();
QBtServiceDiscoverer is used to inquire a remote device for the services it supports. After instantiation, user can call one of the 3 overloads of startDiscovery()
startDiscovery(QBtDevice*) : get all the device_s supported services
startDiscovery(QBtDevice*,QBtConstants::!ServiceClass) : get all the device_s supported services whose UUID equals to the given
startDiscovery(QBtDevice*,QBtConstants::!ServiceProtocol) : get all the device_s supported services whose mechanism contains the service protocol given as argument
Use getInquiredServices() to get the services found so far or connect to the SIGNAL newServiceFound(const QBtDevice&, QBtService) to be reported each time a service is found.
Example: inquire a device (variable name remoteDevice) for all the Serial Port Protocols (SPP) it supports.
QBtServiceDiscoverer* serviceDiscoverer = new QBtServiceDiscoverer(this);
connect (serviceDiscoverer, SIGNAL(newServiceFound(const QBtDevice&, const QBtService&)),
this, SLOT (handlerFunction(const QBtDevice&, const QBtService& )));
serviceDiscoverer->startDiscovery (remoteDevice, QBtConstants::!SerialPort);
QBtServiceAdvertiser is responsible to advertise a given bluetooth service.
After the instantiation of the class, startAdvertising(const QBtService&) can be called to start advertising the given bluetooth service. If successful then advertisingStarted(const QBtService&) signal is emitted.
NOTE: Currently there is no implementation on the Windows platform so after the instantiation of this object, any call to any function will emit an error(QBtServiceAdvertiser::FeatureNotSupported) signal.
QBtService newService;
newService.setName(p_ptr->trService->getName());
newService.setClass(QBtConstants::!SerialPort);
newService.setCommPort(aChannel);
newService.addProtocol(QBtConstants::L2CAP);
newService.addProtocol(QBtConstants::RFCOMM);
QBtServiceAdvertiser* advertiser = new QBtServiceAdvertiser(this);
advertiser->!StartAdvertising(service);
QBtObjectExchangeClient is used to connect to a remote OBEX server and send or recieve files or raw data.
Example connecting to a remote OBEX server. At successful connection user send a file to the server.
Header
#include <QBluetoothZero>
class FileSender
{
Q_OBJECT
public:
FileSender();
protected:
void Setup();
private slots:
void SendFile();
private:
QBtObjectExchangeClient* client;
}
Source
FileSender::FileSender()
{
Setup();
}
void FileSender::Setup()
{
client = new QBtObjectExchangeClient(this);
connect(client, SIGNAL(connectedToServer()), this,SLOT(SendFile()));
client->connectToServer(remoteDevice, remoteService); // remoteDevice & remoteService are acquired from the previous examples
}
void FileSender::SendFile()
{
client->putFile("C:\\picture.jpg");
}
QBtObjectExchangeServer is used to create an OBEX server. After instantiation user can call startServer(const QString&) to start the server. The feedback from the server_s operations is given through SIGNALS.
QBtObjectExchangeServer* server = new QBtObjectExchangeServer(this);
server->startServer("MyObexServer");
In this case we use QBtSerialPortClient. Call connect(const QBtDevice&, const QBtService&) to connect to a remote Serial Port (SPP) Server. If successfull client can send data using sendData(const QString &) function and reports received data through SIGNAL dataReceived(const QString).
QBtSerialPortServer is used. Call startServer(const QString&) to start server and set the name of the publishing service and then wait for a client to connect. When a client is connected, it is reported through clientConnected(QBtAddress) SIGNAL. At this point server is able to send data through sendData(const QString) and the data received are reported through dataReceived(QString).
On the Windows implementation side, the bluetooth functions are provided by the Bluesoleil SDK. So in order to use the Windows implementation, the developer and the end users must have Bluesoleil drivers installed (version 6.4 and on). I know that this restriction is a drawback but I had a couple of months of experience on that SDK so it was the only chance for me to make a Windows implementation at this moment...but it works.
The Win Serial port functions are provided by Thierry Schneider through Tserial_event:
Copyright @ 2001-2002 Thierry Schneider
thierry@tetraedre.com
This project is licensed under the Apache License, Version 2.0.
A few code portions are used from other Nokia code examples thus in the root directory of the project there are these two files:stating the license of each.