我想搜索藍牙設備並列出它們,但我從documenation下面的代碼不起作用。如何枚舉使用Qt的藍牙設備
BluetoothDevices::BluetoothDevices(QObject *parent) : QObject(parent)
{
}
// search Bluetooth devices
void BluetoothDevices::startDeviceDiscovery()
{
qDebug() << "Bluetooth discovery started";
// Create a discovery agent and connect to its signals
//QBluetoothDeviceDiscoveryAgent *discoveryAgent = new QBluetoothDeviceDiscoveryAgent(this);
discoveryAgent = new QBluetoothDeviceDiscoveryAgent(this);
connect(discoveryAgent, SIGNAL(deviceDiscovered(QBluetoothDeviceInfo)),
this, SLOT(deviceDiscovered(QBluetoothDeviceInfo)));
// Start a discovery
discoveryAgent->start();
}
void BluetoothDevices::deviceDiscovered(const QBluetoothDeviceInfo &device)
{
qDebug() << "Found new device:" << device.name() << '(' << device.address().toString() << ')';
}
在主窗口中我開始搜索:
void MainWindow::on_pushButtonSearchBluetooth_clicked()
{
bluetoothDevices.startDeviceDiscovery();
}
我希望deviceDiscovered()
插槽被調用與該設備的名稱,因爲它被發現,但此插槽不會被調用。發起發現後,我從來沒有聽到任何迴音。當我通過控制面板手動搜索藍牙設備時,它確實發現了幾臺筆記本電腦。我還需要通過我的應用程序來找到它們嗎?
我使用的是Windows 7和Qt 5.5。
OS X. 您的意思是'QBluetoothDeviceDiscoveryAgent ::錯誤「?我讓它工作(顯示錯誤消息),但不是與你的班級。 – zar