Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Bluetooth Pairing

Bluetooth Pairing

Scheduled Pinned Locked Moved General and Desktop
bluetoothpair
1 Posts 1 Posters 1.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    saviomuniz
    wrote on last edited by saviomuniz
    #1

    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;
    }

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved