[Interest] [Qt Bluetooth] How to choose local adapter when connecting to service with QBluetoothSocket?

Alexander Blasche alexander.blasche at qt.io
Mon Nov 28 08:11:08 CET 2016



> -----Original Message-----
> From: Interest [mailto:interest-bounces+alexander.blasche=qt.io at qt-
> project.org] On Behalf Of Ayberk Özgür
> Sent: Saturday, 26 November 2016 12:35
> To: interest at qt-project.org
> Subject: Re: [Interest] [Qt Bluetooth] How to choose local adapter when
> connecting to service with QBluetoothSocket?
> 
> Hi Alexander, thanks for your reply.
> 
> It's not noted in the API but given a `QBluetoothSocket`, I was wondering what
> `socketDescriptor` corresponds to and whether I can use that somehow to
> obtain the socket pointer that can be used with Bluez'
> `bind()`?

The answer is yes and no. You cannot use sokcetDescriptor() as the obtained socket is already set up when you get it. What you can do is to use setSocketDescriptor() though. You could do the manual setup in your code and then call it. At least at a first glance I see no obstacle. Make sure you pass the correct socketState to setSocketDescriptor(). 

In general checkout qbluetoothsocket_bluez.cpp if you want to check internal details.

> 
> In any case, is there planned support for binding a `QBluetoothSocket` to a
> `QBluetoothAddress`? Should I open a feature request in the issue tracker?

That's the first step. Otherwise it gets lost in time. However I have to be open in saying that it is a rather rare feature with a potential workaround in setSocketDescriptor() already. Other platforms do not support this at all which makes an API addition rather less likely.

> As a final note: On various Android devices (that already have Bluetooth
> adapters on board), I attached external dongles via OTG and they are indeed
> listed by `lsusb`. However, nothing happens as far as the Bluetooth stack is
> concerned, I don't even think there is any support for enumerating adapters in
> the Android Bluetooth stack.

There are API elements which suggest that it is possible (BluetoothAdapter::getDefaultAdapter()) but at least the public docs have no way of enumerating anything. Unfortunately, this doesn't make the case for an adapter selection stronger.

In fact, in Qt 6.0 I'll probably remove the official support and just leave a less public way of selecting the adapter in the code base.

--
Alex

> On 25.11.2016 12:35, Alexander Blasche wrote:
> >
> >> -----Original Message-----
> >> From: Interest [mailto:interest-bounces+alexander.blasche=qt.io at qt-
> >> project.org] On Behalf Of Ayberk Özgür
> >> Sent: Friday, 25 November 2016 09:39
> >> To: interest at qt-project.org
> >> Subject: [Interest] [Qt Bluetooth] How to choose local adapter when
> >> connecting to service with QBluetoothSocket?
> >>
> >> Hello,
> >>
> >> In the presence of multiple Bluetooth adapters, is it possible to
> >> specify which local adapter to use when creating a QBluetoothSocket
> >> or calling QBluetoothSocket::connectToService()?
> > The local adapter cannot be chosen everywhere. The following API elements
> support the feature you are describing:
> >
> > QBluetoothLocalDevice(QBluetoothAddress, , QObject*)
> > QBluetoothDeviceDiscoveryAgent(QBluetoothAddress, QObject*)
> > QBluetoothServiceDiscoveryAgent(QBluetoothAddress, QObject*)
> > QBluetoothServer::listen(QBluetoothAddress, QString)
> >
> > None of the other classes has support for it.
> >
> >> I'm interested in Linux/BlueZ as well as Android (where it is not
> >> even clear whether multiple Bluetooth adapters are supported by the
> >> Bluetooth stack).
> > The behaviour above was tested for Bluez. In theory this should work on
> Android as well but since I have yet to get an Android device that actually has
> two adapters it was never tested and I would not rule out essential
> implementation details missing. In fact, I have even seen comments indicating
> that Android as platform was not really tested for such a setup. There might be
> problems there too.
> >
> >
> > --
> > Alex
> > _______________________________________________
> > Interest mailing list
> > Interest at qt-project.org
> > http://lists.qt-project.org/mailman/listinfo/interest
> 
> --
> Ayberk Özgür, Doctoral Researcher
> CHILI Laboratory, EPFL
> www.ayberkozgur.com
> 
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest


More information about the Interest mailing list