我正在尝试开发一个应用程序,它使用bluez stack以及pulseaudio和ofono来连接到手机,并实现媒体播放(A2DP)、媒体控制(AVRCP)和基于免提的电话(HFP)等任务。当我通过
bluetoothctl
,它会自动连接到所有可用的配置文件,因此通过我的程序使用所有配置文件A2DP、AVRCP、HFP是可以实现的。如果我没有使用
蓝牙CTL
,免提/HFP调制解调器未在OFNO中启用/通电。
然而,当我在Qt中使用QBluetoothSocket并使用配置文件连接时,总会有一个配置文件未连接。例如,连接到免提模式时,电话功能正常,但媒体控制不起作用。简而言之,我希望能够连接到蓝牙作为
蓝牙CTL
做我对Qt的了解如下(简而言之):
static const QList<QBluetoothUuid> audioUuids = QList<QBluetoothUuid>()
<< QBluetoothUuid::HeadsetAG
<< QBluetoothUuid::AV_RemoteControlTarget;
..
void BtConnection::setConnection(int index)
{
if(m_bluetoothSocket == nullptr) {
m_bluetoothSocket = new QBluetoothSocket(QBluetoothServiceInfo::RfcommProtocol);
qDebug() << "Created Bluetooth Socket";
}
if(m_bluetoothSocket != nullptr) {
connect(m_bluetoothSocket, SIGNAL(connected()), this, SLOT(connected()));
connect(m_bluetoothSocket, SIGNAL(disconnected()), this, SLOT(disconnected()));
connect(m_bluetoothSocket, SIGNAL(error(QBluetoothSocket::SocketError)),
this, SLOT(connectionError(QBluetoothSocket::SocketError)));
}
m_device = get(index);
QList<QBluetoothUuid>::const_iterator uuid;
for (uuid = audioUuids.begin(); uuid != audioUuids.end(); ++uuid) {
if(m_device.serviceUuids().indexOf(*uuid) > 0) {
if(m_bluetoothSocket != nullptr) {
qDebug() << "*****Connecting... " << *uuid;
m_bluetoothSocket->connectToService(m_device.address(), *uuid);
return;
}
}
}
qDebug() << "*****Cannot connect to service...";
}
如果您不清楚,我愿意发布更多代码。非常感谢您对如何使用Qt as连接蓝牙的任何帮助
蓝牙CTL
做