Bluetooth + QtQuick <-> Qt : how?
Hi
Its my first time i try to create a ui application for mobile, and also that im trying to use bluetooth :)
Im trying to create a harmattan application that connects and read from a device over bluetooth rfcomm.
Since all the UI should be done using qtquick, i did that.
I took the scanner.qml page from the declarative-scanner example to scan for my device and choose it.
now here's the catch: i would like to do the communication in Qt, for efficiency reasons, for flexibility, and also because the device sends binary packets, and im not sure how easy/efficient would be to parse them with javascript.
So what i did was taking the chatclient class from the btchat example and integrating it.
now the problem:
the scanner page returns Qml BluetoothService elements, while Qt needs a QBluetoothServiceInfo object to connect a bluetooth socket to the service.
Thanks to google, i found out that Qml BluetoothService is actually backed up by a QDeclarativeBluetoothService class, which in fact contains a QBluetoothServiceInfo object and even has a method to return that pointer.
so the easy option here would be to return the BluetoothService property to Qt via parentObject->property("") , and then convert() the resulting QVariant.
Unfortunately, the source code for QDeclarativeBluetoothService is not present in the SDK, so essentially i dont have the definition, and thus cannot cast the BluetoothService to QDeclarativeBluetoothService.
also, the method i need is not Q_INVOKABLE, so i cannot use invoke().
do you have any idea how i can share the object with a QObject class in Qt?
Re: Bluetooth + QtQuick <-> Qt : how?
i was thinking to a workaround: maybe i can have the discovery process in Qt, and exchange a list with the name of the devices between qt and qml?
then i should just forward the element clicked event from qml back to qt.
Is it possible?
thanks
ps: is a QBluetoothSocket running in a separate thread? and should all data available be always read, even if i want to discard some of it ?
Re: Bluetooth + QtQuick <-> Qt : how?
Yes, it is very much possible. check on wiki you will find some article as well.
Re: Bluetooth + QtQuick <-> Qt : how?
Hi,
I have similar requirement as Tedtrubo. I am trying to connect to a bluetooth device and send and receive data to it using bluetooth socket.
- In QML scanner example, my device is not found during scanning
- In Qt scanner example (bscanner), it finds my device, But when I try to connect the device using socket, the applcation crashes.
I use
QBluetoothSocket *socket = new QBluetoothSocket();
if (!socket){
qDebug()<< "SOCKET IS NULL";
return;
}
socket->connectToService(address, QBluetoothUuid::SerialPort, QIODevice::ReadOnly);
address is the one returned by device discovery. Seems to be valid in ab:cd:ef:gh:ij:kl format. Here the problem is, ConnectToService crash with "Thread has crashed: A data abort exception has occurred accessing 0x3c." message.
What am I doing wrong ??
Re: Bluetooth + QtQuick <-> Qt : how?
[QUOTE=chanderk;899782]Hi,
I have similar requirement as Tedtrubo. I am trying to connect to a bluetooth device and send and receive data to it using bluetooth socket.
- In QML scanner example, my device is not found during scanning
- In Qt scanner example (bscanner), it finds my device, But when I try to connect the device using socket, the applcation crashes.
I use
QBluetoothSocket *socket = new QBluetoothSocket();
if (!socket){
qDebug()<< "SOCKET IS NULL";
return;
}
socket->connectToService(address, QBluetoothUuid::SerialPort, QIODevice::ReadOnly);
address is the one returned by device discovery. Seems to be valid in ab:cd:ef:gh:ij:kl format. Here the problem is, ConnectToService crash with "Thread has crashed: A data abort exception has occurred accessing 0x3c." message.
What am I doing wrong ??[/QUOTE]
Hello!
What device(s) are you testing on? If Symbian, what capabilities do you have enabled?
Br,
Villep
Re: Bluetooth + QtQuick <-> Qt : how?
@villep I am testing with N8 (belle). I use TARGET.CAPABILITY = ReadDeviceData LocalServices WriteDeviceData
My example application running on N8, and I am trying to establish a socket connection with an external device (not a mobile).
Re: Bluetooth + QtQuick <-> Qt : how?
[QUOTE=chanderk;899823]@villep I am testing with N8 (belle). I use TARGET.CAPABILITY = ReadDeviceData LocalServices WriteDeviceData
My example application running on N8, and I am trying to establish a socket connection with an external device (not a mobile).[/QUOTE]
Try adding NetworkServices to capabilities.
Br,
Villep