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. How to force a Bluetooth pairing pin?
Forum Updated to NodeBB v4.3 + New Features

How to force a Bluetooth pairing pin?

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 816 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.
  • L Offline
    L Offline
    lilimah
    wrote on last edited by
    #1

    Hey,

    i am writing an apllication in qt on my laptop (Debian 8). This applicatio should connect to other devices like my android smartphones (4.4.2, 5.0.2, 6.0.0). This work great, i can pair and connect, but i want the smartphone and the application to show a pin for pairing. I looked in the documentation and it says
    "This signal is only emitted for pairing requests issues by calling requestPairing()." (http://doc.qt.io/qt-5/qbluetoothlocaldevice.html#pairingDisplayConfirmation).

    So means this, QT tries first to connect without pin and will use the pin just if something goes wrong? How can i force it to show always a pin? (There is no need for a custom pin.) Some parts of my code:

    localDevice = new QBluetoothLocalDevice();
    
    connect(localDevice, SIGNAL(pairingFinished(QBluetoothAddress,QBluetoothLocalDevice::Pairing)), this, SLOT(pairingDone(QBluetoothAddress,QBluetoothLocalDevice::Pairing)));
    
    connect(localDevice, SIGNAL(pairingDisplayConfirmation(const QBluetoothAddress&, QString)), this, SLOT(pairingMyDisplayConfirmation(const QBluetoothAddress&, QString)));
    
    connect(localDevice, SIGNAL(pairingDisplayPinCode(QBluetoothAddress,QString)), this, SLOT(displayPin(QBluetoothAddress,QString)));
    

    ...

    void MainWindow::doPairingAction()
    {
        if (ui->list->count() == 0){
            return;
        }
    
        if (ui->selectedMac->text().length() == 0 || ui->selectedName->text().length() == 0){
            return;
        }
    
        QBluetoothAddress address (ui->selectedMac->text());
        if (ui->pair->text() == "Pair") {
            qDebug() << "pair " << address;
    
    
    
            localDevice->requestPairing(address, QBluetoothLocalDevice::Paired);
        } else if (ui->pair->text() == "Unpair") {
            localDevice->requestPairing(address, QBluetoothLocalDevice::Unpaired);
        }
    }
    
    void MainWindow::pairingMyDisplayConfirmation(const QBluetoothAddress &address, QString pin){
        qDebug() << "#PAIRING_DISPLAY_CONFIRMATION_PIN: " << pin << "for" << address;
    }
    
    
    void MainWindow::pairingDone(const QBluetoothAddress &address, QBluetoothLocalDevice::Pairing pairing)
    {
        QList<QListWidgetItem *> items = ui->list->findItems(address.toString(), Qt::MatchContains);
    
        if (pairing == QBluetoothLocalDevice::Paired || pairing == QBluetoothLocalDevice::AuthorizedPaired ) {
            for (int var = 0; var < items.count(); ++var) {
                QListWidgetItem *item = items.at(var);
                item->setTextColor(QColor(Qt::green));
                setPairStatus(true);
                qDebug() << "pair " << address << "success";
            }
        } else {
            for (int var = 0; var < items.count(); ++var) {
                QListWidgetItem *item = items.at(var);
                item->setTextColor(QColor(Qt::red));
                setPairStatus(false);
                qDebug() << "pair " << address << "failed";
            }
        }
    }
    
    
    void MainWindow::displayPin(const QBluetoothAddress &address, QString pin)
    {
        qDebug() << "#DISPLAY_PIN: " << pin << "for" << address;
    }
    

    I know there is no dialog, but if i could debug the message for pin request or confirmation would be great.

    Thank You.

    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