简体   繁体   English

如何用QT强制蓝牙配对引脚?

[英]How to force a bluetooth pairing pin with QT?

i am writing an apllication in qt on my laptop (Debian 8). 我在我的笔记本电脑(Debian 8)上用qt编写了一个附件。 This applicatio should connect to other devices like my android smartphones (4.4.2, 5.0.2, 6.0.0). 此应用程序应连接到其他设备,例如我的android智能手机(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(). 该信号仅在通过调用requestPairing()配对请求发出时发出。

( http://doc.qt.io/qt-5/qbluetoothlocaldevice.html#pairingDisplayConfirmation ). 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? 因此,这意味着QT首先尝试不使用引脚进行连接,并且即使出现问题也将使用该引脚吗? 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. 谢谢。

So means this, QT tries first to connect without pin and will use the pin just if something goes wrong? 因此,这意味着QT首先尝试不使用引脚进行连接,并且即使出现问题也将使用该引脚吗? How can i force it to show always a pin? 我如何强制它始终显示图钉? (There is no need for a custom pin.) Some parts of my code: (不需要自定义图钉。)我的代码的某些部分:

There are two kind of pairing method, one is general bonding and the other one is dedicated bonding. 配对方法有两种,一种是通用绑定,另一种是专用绑定。 The first one just like your description, ie first try to connect some profile and the security module would request pairing. 第一个就像您的描述,即首先尝试连接一些配置文件,安全模块将请求配对。 the second one is just pairing but does not connect profile actually. 第二个只是配对,但实际上并没有连接个人资料。

Regarding to your question, you need care whether your device are using the pin code or SSP, if for the second one, generally they are using "just work" method and then you can not print the pin code request information since they are using the different function. 关于您的问题,您需要注意您的设备是使用密码还是SSP,如果对于第二个设备,通常使用的是“ just work”方法,那么您将无法打印密码请求信息,因为它们正在使用密码。不同的功能。 if your device using the pin code, just unpair it and then pair again I believe it should be pin dialog appears. 如果您的设备使用PIN码,只需取消配对,然后再次配对,我相信应该会出现PIN对话框。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM