2016-11-23 1 views

Antwort

0

Ab Qt 5.6.2, gibt es keine solche Funktionalität noch abgesehen von QBluetoothLocalDevice(QBluetoothAddress), QBluetoothDeviceDiscoveryAgent(QBluetoothAddress), QBluetoothServiceDiscoveryAgent(QBluetoothAddress) und QBluetoothServer::listen(QBluetoothAddress). Diese wären nur unter Linux und nicht unter Android sinnvoll, da der Android-Bluetooth-Stack zumindest noch nicht mehrere Dongles zu unterstützen scheint.

jedoch auf Linux mit BlueZ, ist Folgendes möglich den lokalen Adapter mit der BlueZ c API zur Auswahl:

#include <sys/socket.h> 
#include <bluetooth/bluetooth.h> 
#include <bluetooth/rfcomm.h> 

... 

QBluetoothSocket* socket = new QBluetoothSocket(QBluetoothServiceInfo::RfcommProtocol); 

struct sockaddr_rc loc_addr; 
loc_addr.rc_family = AF_BLUETOOTH; 

int socketDescriptor = ::socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM); 
if(socketDescriptor < 0){ 
    qCritical() << strerror(errno); 
    return; 
} 

const char* localMacAddr = "XX:XX:XX:XX:XX:XX"; //MAC address of the local adapter 
str2ba(localMacAddr, &(loc_addr.rc_bdaddr)); 

if(bind(socketDescriptor, (struct sockaddr*)&loc_addr, sizeof(loc_addr)) < 0){ 
    qCritical() << strerror(errno); 
    return; 
} 

if(!socket->setSocketDescriptor(socketDescriptor, QBluetoothServiceInfo::RfcommProtocol, QBluetoothSocket::UnconnectedState)){ 
    qCritical() << "Couldn't set socketDescriptor"; 
    return; 
} 

socket->connectToService(...); 

Das Projekt .pro muss Folgendes enthalten:

CONFIG += link_pkgconfig 
PKGCONFIG += bluez 

Die entsprechenden Feature-Anforderung, um dies möglicherweise in die Qt-APIs zu integrieren: https://bugreports.qt.io/browse/QTBUG-57382

Verwandte Themen