I'm new to Qt framework. This is my first C++ implementation in real world applications. I was facing problem in preparing this bluetooth based application. I went through Qt documentation too, but it didn't work. Code is : CLASS HEADER
#ifndef MAINCLASS_H
#define MAINCLASS_H
#include <QObject>
#include <QBluetoothServiceDiscoveryAgent>
#include <QBluetoothServiceInfo>
#include <QBluetoothLocalDevice>
class MainClass : public QObject
{
Q_OBJECT
public:
explicit MainClass(QObject *parent = 0);
~MainClass();
void startDiscovery(void);
signals:
public slots:
void onDiscovery(const QBluetoothServiceInfo &serviceInfo);
private:
QBluetoothServiceDiscoveryAgent *discoveryAgent;
QBluetoothLocalDevice *bluetoothDevice;
};
#endif // MAINCLASS_H
// MEMBER DEFINITIONS
#include "mainclass.h"
#include <QDebug>
MainClass::MainClass(QObject *parent) : QObject(parent)
{
bluetoothDevice = new QBluetoothLocalDevice();
QBluetoothAddress bluetoothAddress = bluetoothDevice->address();
discoveryAgent = new QBluetoothServiceDiscoveryAgent(bluetoothAddress);
connect(discoveryAgent, SIGNAL(serviceDiscovered(QBluetoothServiceInfo)),
this, SLOT(onDiscovery(QBluetoothServiceInfo)));
discoveryAgent->setUuidFilter(QBluetoothUuid(QBluetoothUuid::ObexObjectPush));
discoveryAgent->start();
if(!discoveryAgent->isActive())
qDebug()<<"Not active";
if(discoveryAgent->error() != QBluetoothServiceDiscoveryAgent::NoError)
qDebug()<<discoveryAgent->errorString();
}
MainClass::~MainClass()
{
delete(discoveryAgent);
}
void MainClass::onDiscovery(const QBluetoothServiceInfo &serviceInfo)
{
qDebug() << "Discovered service on"
<< serviceInfo.device().name() << serviceInfo.device().address().toString();
qDebug() << "\tService name:" << serviceInfo.serviceName();
qDebug() << "\tDescription:"
<< serviceInfo.attribute(QBluetoothServiceInfo::ServiceDescription).toString();
qDebug() << "\tProvider:"
<< serviceInfo.attribute(QBluetoothServiceInfo::ServiceProvider).toString();
qDebug() << "\tL2CAP protocol service multiplexer:"
<< serviceInfo.protocolServiceMultiplexer();
qDebug() << "\tRFCOMM server channel:" << serviceInfo.serverChannel();
}
Main Function
#include "mainclass.h"
int main()
{
MainClass obj;
}
This piece of code wasn't showing lists of surrounding bluetooth devices. Any suggestions?