Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
New Developer
Posts: 8
Registered: ‎03-25-2013
My Device: Blackberry Z10 / Z30 / Playbook
My Carrier: simquadrat.de / sipgate.de

Using QtConnectivity for Bluetooth

Hi,

 

has anyone QtConnectivity for Bluetooth successful in use ?

I have some problem with QtConnectivity Bluetooth API.

 

To use QBluetoothSocket you need (see connectToService ) either the Bluetooth Uuid with Address from the device or a discovered QBluetoothServiceInfo instance from the QBluetoothServiceDiscoveryAgent.

 

When I use the connectToService with the address and port parameter, then I see in the log output on my BB device "Connecting to port is not supported on QNX". The function is not implemented yet, right?

 

Ok, for the next "connectToService" method I need the Bluetooth address and Uuid. I can get this parameters from the QBluetoothDeviceDiscoveryAgent. So I used it and the agent discovered every device but not the Uuids.

 

Ok, then I use the QBluetoothServiceDiscoveryAgent (I think this use the Bluetooth SDP) but this does not work. I see in the log output on my BB device

"Device discovery finished...

...starting service discovery "

but they scan and scan and scan ..... doesnt stop scanning and found nothing.

 

I have push my example on GitHub and I hope somebody can help or explain me the problem.

 

And my next question is, is QtConnectivity Bluetooth API support Bluetooth 4.0 + Low Energy ? Or which Bluetooth stack use QtConnectivity, the open source BlueZ stack and which version or the QNX native Bluetooth stack (btxxxx.h)?

 

And yes, I have a runnable code with QBluetoothServiceDiscoveryAgent

Ok, its with Qt5 on my Desktop :-)

 

New Developer
Posts: 17
Registered: ‎11-08-2012
My Device: Z10 Limited Edition
My Carrier: H3G - Italy

Re: Using QtConnectivity for Bluetooth

Hello bjoe,

these days I'm experimenting with how to use the module QtConnectivity.
The official ducumentazione is almost nothing, but I found a few examples made for Nokia and Qt applications, so I wrote this code that allows me to connect with a BT module for Arduino.

void BluetoothService::peerToDevice() {
	if(m_btAvailable) {
		m_btLocalDevice->setHostMode(QBluetoothLocalDevice::HostDiscoverable);

		QBluetoothDeviceDiscoveryAgent *discoveryAgent = new QBluetoothDeviceDiscoveryAgent(this);

		connect(discoveryAgent,	SIGNAL(deviceDiscovered(const QBluetoothDeviceInfo&)), this, SLOT(deviceDiscovered(const QBluetoothDeviceInfo&)));

		discoveryAgent->start();
	}
}
...
...
void BluetoothService::deviceDiscovered(const QBluetoothDeviceInfo &deviceInfo) {
	qDebug() << "SLOT - deviceDiscovered";
	qDebug() << deviceInfo.name() << " : " << deviceInfo.address().toString();

	if (deviceInfo.name() == HOST_NAME) {
		if (m_btSocket == NULL) {
			m_btSocket = new QBluetoothSocket(QBluetoothSocket::RfcommSocket);
			connect(m_btSocket, SIGNAL(connected()), this, SLOT(deviceConnected()));
			connect(m_btSocket, SIGNAL(error(QBluetoothSocket::SocketError)), this, SLOT(socketError(QBluetoothSocket::SocketError)));
			connect(m_btSocket, SIGNAL(readyRead()), this, SLOT(readSocket()));
			QBluetoothUuid btUuid = QBluetoothUuid::SerialPort;
			m_btSocket->connectToService(deviceInfo.address(), btUuid);
		}
	}
}

HOST_NAME is the name of the BT module.

New Developer
Posts: 8
Registered: ‎03-25-2013
My Device: Blackberry Z10 / Z30 / Playbook
My Carrier: simquadrat.de / sipgate.de

Re: Using QtConnectivity for Bluetooth

Hi GeilPMagico,

 

ah, you set the Bluetooth Service Class UUID manually

QBluetoothUuid btUuid = QBluetoothUuid::SerialPort;

m_btSocket->connectToService(deviceInfo.address(), btUuid);



 


 

Thanks for the hint, I had not thought of yet.

 

But my wish is to discovery the service via the QBluetoothXXXXDiscoveryAgent automatically.

New Developer
Posts: 17
Registered: ‎11-08-2012
My Device: Z10 Limited Edition
My Carrier: H3G - Italy

Re: Using QtConnectivity for Bluetooth

[ Edited ]

Bluetooth communication takes place via SSL communication.

 

QBluetoothUuid :: SerialPort is the unique identifier that allows QBluetoothSocket to open the serial port.

 

The connection is opened the door to the address mentioned above is taken from QBluetoothDeviceInfo::address() automatically detected by QBluetoothDeviceDiscoveryAgent.

 

For more information on how to use QBluetoothUuid you can watch here: http://doc.qt.digia.com/qtmobility-1.2.0/qbluetoothuuid.html#ServiceClassUuid-enum