C++ 连接到经典蓝牙设备时Qt蓝牙卡滞
我目前正在尝试使用经典BT从外围设备读取蓝牙信号,以控制我的Qt应用程序。稍后我可能会使用一个小的BT操纵杆,但现在我正在尝试连接到配对耳机上的按钮 我以前C++ 连接到经典蓝牙设备时Qt蓝牙卡滞,c++,linux,qt,bluetooth,bluetooth-peripheral,C++,Linux,Qt,Bluetooth,Bluetooth Peripheral,我目前正在尝试使用经典BT从外围设备读取蓝牙信号,以控制我的Qt应用程序。稍后我可能会使用一个小的BT操纵杆,但现在我正在尝试连接到配对耳机上的按钮 我以前 ..通过QBluetoothDeviceDiscoveryAgent扫描远程设备,它返回我的耳机的QBluetoothDeviceInfo …使用QBluetoothServiceDiscoveryAgent扫描该设备上的服务,该工具返回QBluetoothServiceInfo和QBluetoothUuid::AV_RemoteContr
QBluetoothDeviceDiscoveryAgent
扫描远程设备,它返回我的耳机的QBluetoothDeviceInfo
QBluetoothServiceDiscoveryAgent
扫描该设备上的服务,该工具返回QBluetoothServiceInfo
和QBluetoothUuid::AV_RemoteControl
socket0 = new QBluetoothSocket(QBluetoothServiceInfo::L2capProtocol);
connect(socket0, &QBluetoothSocket::stateChanged, this , &BluetoothController::socketStateChanged);
connect(socket0, &QBluetoothSocket::readyRead, this, &BluetoothController::readSocket);
connect(socket0, &QBluetoothSocket::connected, this, &BluetoothController::serverConnected);
connect(socket0, &QBluetoothSocket::disconnected, this, &BluetoothController::serverDisconnected);
connect(socket0, QOverload<QBluetoothSocket::SocketError>::of(&QBluetoothSocket::error),
this, &BluetoothController::serverError);
QBluetoothAddress address = info.device().address();
QIODevice::ReadOnly);
socket0->connectToService(address, QBluetoothUuid::AV_RemoteControl, QIODevice::ReadOnly);
socket0=新的QBluetoothSocket(QBluetoothServiceInfo::L2Approtocol);
连接(socket0、&QBluetoothSocket::stateChanged、this、&BluetoothController::socketStateChanged);
连接(socket0,&QBluetoothSocket::readyRead,this,&BluetoothController::readSocket);
连接(socket0,&QBluetoothSocket::connected,this,&BluetoothController::serverConnected);
连接(socket0,&QBluetoothSocket::disconnected,this,&BluetoothController::serverDisconnected);
连接(socket0,QOverload::of(&QBluetoothSocket::error),
这是一个错误(&BluetoothController::serverError);
QBluetoothAddress=info.device().address();
QIODevice::只读);
socket0->connectToService(地址,QBluetoothUuid::AV_远程控制,QIODevice::只读);
此时,套接字状态将更改为ConnectionState,不会通过错误,但也不会触发myreadyRead()
函数您正试图以非root用户身份运行软件。Linux蓝牙协议栈检查两个功能,这两个功能是错误日志中提到的操作所必需的-
CAP\u NET\u RAW
和CAP\u NET\u ADMIN
。功能是特权用户(root)的“全有或全无”方法的替代方法。这为无权限用户提供了更细粒度的权限控制,因此它只能获得root用户的一部分权限。有关更多详细信息,请阅读man 7功能
有几种利用功能的技术,其中之一是文件功能。使用setcap(8)
可以达到预期效果,如下所示:
sudo setcap'cap\u net\u raw,cap\u net\u admin+eip'您的应用程序
感谢您的帮助。我试图在我的应用程序上使用该命令,但没有成功。错误依然存在,除此之外,我的应用程序的其他部分也出现了其他错误,无法加载插件“/usr/lib/x86_64-linux-gnu/gstreamer-1.0/libgstqt5videosink.so':/usr/lib/x86_64-linux-gnu/libQt5OpenGL.so.5:symbol-znk11qfontEngine10glyphcacheepkns\u 11qformaterk10qtransform版本Qt 5\u PRIVATE\u文件中未定义API具有链接时间引用的libQt5Gui.so.5无法创建qtquick2videosink。确保它安装正确,这与gstreamer插件有关,可能是由于不兼容。它动态加载共享对象,但找不到必要的符号。与原始版本无关。