Bluetooth Pairing



  • Hello everyone,

    I'm having issues on trying to create a program that works based on bluetooth. I managed to get the available devices, but I can't quite understand how I can do to pair an available device. This is what I've tried so far:

    pairdevices.h

    #ifndef PAIRDEVICES_H
    #define PAIRDEVICES_H

    #include <QObject>
    #include <QBluetoothLocalDevice>
    #include <QBluetoothDeviceDiscoveryAgent>
    #include <QBluetoothServiceDiscoveryAgent>

    class PairDevices : public QObject
    {
    Q_OBJECT
    public:
    explicit PairDevices(QObject *parent = 0);

    private:
    QBluetoothLocalDevice *myDevice;

    signals:

    public slots:
    void ReceiveAddress (const QBluetoothServiceInfo &serviceInfo);
    void finished (QBluetoothAddress address,QBluetoothLocalDevice::Pairing pairing);
    };

    #endif // PAIRDEVICES_H

    pairdevices.cpp

    #include "pairdevices.h"
    #include <QDebug>
    #include <QBluetoothLocalDevice>

    PairDevices::PairDevices(QObject *parent) : QObject(parent),myDevice(new QBluetoothLocalDevice)
    {
    connect (myDevice, SIGNAL(pairingFinished(QBluetoothAddress,QBluetoothLocalDevice::Pairing)), this, SLOT (finished(QBluetoothAddress,QBluetoothLocalDevice::Pairing)));

    }

    void PairDevices::ReceiveAddress(const QBluetoothServiceInfo &serviceInfo)
    {
    myDevice->setHostMode(QBluetoothLocalDevice::HostDiscoverable);
    myDevice->requestPairing(serviceInfo.device().address(),QBluetoothLocalDevice::Paired);
    myDevice->pairingConfirmation(true);
    }

    void PairDevices::finished(QBluetoothAddress address, QBluetoothLocalDevice::Pairing pairing)
    {
    qDebug() << "finished";
    qDebug() << pairing;
    }


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.