这里是我的代码:我有一个叫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)。 –