我是 Qt、Symbian 设备和蓝牙的新手。
我必须设置一个 RFCOMM 服务器来接收来自仅支持 SPP 配置文件的蓝牙设备(它是一个密码键盘)的连接。
我在谷歌上搜索并找到了一些示例,如下所示:http ://doc.qt.nokia.com/qtmobility/btchat.html
尝试了一切,但我无法连接它们。两台设备都已配对,但当我尝试连接时失败。
当我询问制造商时,他们说这是因为我手机上的 SPP 服务器无法监听传入连接。
我正在创建 RFCOMM 服务器并像示例一样注册服务,但它仍然无法正常工作。
有人可以帮助我吗?
我正在使用 Qt 和 QtMobility 1.2.0,我的手机是诺基亚 500 (Symbian^3)。
这是我的代码:
void bluetooth::startServer()
{
QString deviceName;
QBluetoothLocalDevice localDevice;
if (rfcommServer)
return;
localDevice.powerOn();
localDevice.setHostMode(QBluetoothLocalDevice::HostDiscoverable);
deviceName = localDevice.name();
rfcommServer = new QRfcommServer(this);
connect(rfcommServer, SIGNAL(newConnection()), this, SLOT(vConectou())) ;
if( rfcommServer->listen(localDevice.address(),
quint16(rfcommServer->serverPort()) ) )
emit vExibeMsg("Listening");
else
emit vExibeMsg("Error");
serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceRecordHandle,
(uint)0x00010010);
QBluetoothServiceInfo::Sequence classId;
classId << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::SerialPort));
serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceClassIds, classId);
serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceName, tr("Test Server"));
serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceDescription,
tr("Test Bluetooth"));
serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceProvider, deviceName );
serviceInfo.setServiceUuid(QBluetoothUuid(QBluetoothUuid::Rfcomm));
serviceInfo.setAttribute(QBluetoothServiceInfo::BrowseGroupList,
QBluetoothUuid(QBluetoothUuid::PublicBrowseGroup));
QBluetoothServiceInfo::Sequence protocolDescriptorList;
QBluetoothServiceInfo::Sequence protocol;
/*
protocol << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::L2cap));
protocolDescriptorList.append(QVariant::fromValue(protocol));
protocol.clear();
protocol << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::Rfcomm))
<< QVariant::fromValue(quint8(rfcommServer->serverPort()));
protocolDescriptorList.append(QVariant::fromValue(protocol));
protocol.clear();
protocol << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::SerialPort));
protocolDescriptorList.append(QVariant::fromValue(protocol));
*/
protocol << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::Rfcomm))
<< QVariant::fromValue(quint8(rfcommServer->serverPort()));
protocolDescriptorList.append(QVariant::fromValue(protocol));
serviceInfo.setAttribute(QBluetoothServiceInfo::ProtocolDescriptorList,
protocolDescriptorList);
if( serviceInfo.registerService() )
{
emit vExibeMsg("Waiting for connections...");
}
else
{
emit vExibeMsg("Error to create the service");
}
}