×

Discussion Board

Results 1 to 7 of 7

Hybrid View

  1. #1
    Registered User
    Join Date
    Mar 2012
    Posts
    13

    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?

  2. #2
    Registered User
    Join Date
    Mar 2012
    Posts
    13

    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 ?
    Last edited by tedturbo; 2012-06-20 at 21:19.

  3. #3
    Super Contributor
    Join Date
    Jun 2006
    Location
    India
    Posts
    3,037

    Re: Bluetooth + QtQuick <-> Qt : how?

    Yes, it is very much possible. check on wiki you will find some article as well.
    Use [URL="http://qt.nokia.com/products/qt-quick/"]Qt-Quick[/URL] to make your application UI more attractive.

    [URL="http://store.ovi.com/content/271896"]http://store.ovi.com/content/271896[/URL] | [URL="http://store.ovi.com/content/276199"]http://store.ovi.com/content/276199[/URL] |[URL="http://store.ovi.com/content/276202"] http://store.ovi.com/content/276202[/URL] | [URL="http://store.ovi.com/content/280827"]http://store.ovi.com/content/280827[/URL]

  4. #4
    Registered User
    Join Date
    Dec 2007
    Posts
    104

    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 ??

  5. #5
    Nokia Developer Expert
    Join Date
    Jun 2012
    Posts
    55

    Re: Bluetooth + QtQuick <-> Qt : how?

    Quote Originally Posted by chanderk View Post
    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 ??
    Hello!

    What device(s) are you testing on? If Symbian, what capabilities do you have enabled?

    Br,

    Villep

  6. #6
    Registered User
    Join Date
    Dec 2007
    Posts
    104

    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).

  7. #7
    Nokia Developer Expert
    Join Date
    Jun 2012
    Posts
    55

    Re: Bluetooth + QtQuick <-> Qt : how?

    Quote Originally Posted by chanderk View Post
    @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).
    Try adding NetworkServices to capabilities.

    Br,

    Villep

Similar Threads

  1. QtQuick+Bluetooth: stringData is empty
    By DragoslaV in forum [Archived] Qt Mobility Project
    Replies: 9
    Last Post: 2012-06-15, 22:01
  2. how to make qtquick mutiplatform
    By vladest in forum [Archived] Qt Quick
    Replies: 3
    Last Post: 2011-10-19, 05:46
  3. QtQuick 1.1 available?? Help please
    By lukakiarelli in forum [Archived] Qt Quick
    Replies: 4
    Last Post: 2011-06-21, 07:01
  4. QtQuick and QWebFrame::toPlainText()
    By ad5xj in forum [Archived] Qt Quick
    Replies: 1
    Last Post: 2011-04-17, 17:24
  5. QtQuick/QML or Native
    By bluechrism in forum [Archived] Qt Quick
    Replies: 1
    Last Post: 2011-02-27, 22:26

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×