這裏是我的代碼:我有一個叫bluetoothCommunication
的類,我需要放置一些通過藍牙交換數據的方法。在Qt中掃描藍牙設備
bluetoothCommunication::bluetoothCommunication()
{
QBluetoothLocalDevice localDevice;
QString localDeviceName;
//Check if Bluetooth is available on this device
if(localDevice.isValid()){
//Turn Bluetooth on
localDevice.powerOn();
//Read local device name
localDeviceName = localDevice.name();
//Make it visible to others
localDevice.setHostMode(QBluetoothLocalDevice::HostDiscoverable);
//Get connected devices
QList<QBluetoothAddress> remotes;
remotes = localDevice.connectedDevices();
}
}
void bluetoothCommunication::startDeviceDiscovery()
{
qDebug() << "Bluetooth discovery started";
//Create a discovery agent and connect to its signals
QBluetoothDeviceDiscoveryAgent* discoveryAgent = new QBluetoothDeviceDiscoveryAgent();
QObject::connect(discoveryAgent, SIGNAL(deviceDiscovered(QBluetoothDeviceInfo*)), &this, SLOT(deviceDiscovered(QBluetoothDeviceInfo*))); //HERE I HAVE AN ERROR //DON'T KNOW WHERE AND WHY
//Start a discovery
discoveryAgent -> start();
}
我試圖修改從Qt文檔官方的例子(這是下面的),這使我的錯誤在編譯期間,如果我複製並粘貼:
void MyClass::startDeviceDiscovery()
{
// Create a discovery agent and connect to its signals
QBluetoothDeviceDiscoveryAgent *discoveryAgent = new QBluetoothDeviceDiscoveryAgent(this);
connect(discoveryAgent, SIGNAL(deviceDiscovered(QBluetoothDeviceInfo)),
this, SLOT(deviceDiscovered(QBluetoothDeviceInfo)));
// Start a discovery
discoveryAgent->start();
//...
}
但是我嘗試修復它仍然不起作用。隨着錯誤消息:
在成員函數
void bluetoothCommunication::startDeviceDiscovery()
:左值要求作爲 一元&
操作
評論是不適合擴展討論;這個對話已經[轉移到聊天](http://chat.stackoverflow.com/rooms/143526/discussion-on-question-by-elena-scanning-for-bluetooth-devices-in-qt)。 –