Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Problem with qt bluetooth(qml type) [Solved]

Problem with qt bluetooth(qml type) [Solved]

Scheduled Pinned Locked Moved Mobile and Embedded
4 Posts 3 Posters 2.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mostefa
    wrote on last edited by
    #1

    Hello,

    I am working on QtAnroid project, and i have to make a bluetooth connection between a smartphone
    another Bluetooth peripheral (adruino ble shield), i am using qml with QtBluetooth 5.3

    here's a part of my code:

    @ BluetoothService{
    id: blueService
    deviceAddress: "peripheral mac address"
    serviceUuid: "00001100-0000-1000-8000-00805F9B34FB"
    serviceProtocol: BluetoothService.RfcommProtocol
    }

    BluetoothSocket{
        id: blueSocket
        connected: true
        service: blueService
        onErrorChanged: {
            console.log("Error: " + blueSocket.error) //Errors are printed in Application Output underneeth.
            //blueToothText.text = blueSocket.error;
            blueSocket.connected = false;
        }
    
    
        onDataAvailable: {
            console.log("Alone: "+stringData);
            console.log("toString: "+stringData.toString());
            console.log("Length: "+stringData.length);
        }
    
        onConnectedChanged: {
            console.log("Connection: " + connected);
        }
    }@
    

    and when i run the project i have the following error:

    @qt.bluetooth.qml: Could not start server. Error: 5@

    for information when i add :

    @BluetoothDiscoveryModel{

    id: btModel
    running: true
    discoveryMode: BluetoothDiscoveryModel.FullServiceDiscovery
    onServiceDiscovered: {
    console.log("Found new service ",
    service.deviceAddress,";",
    service.serviceDescription,";",
    service.serviceName,";",
    service.servicePort,";",
    service.serviceProtocol,";",
    service.serviceUuid);
    }
    }
    @

    no service appears in the console, is it normal that i dont show any service of the connected peripheral?if yes is it recommended to use qt bluetooth c++ api instead of qml bluetooth api?

    Any help is appreciated.
    Thank you!

    Edit:
    [Solved] thanks to X-Krys

    1 Reply Last reply
    0
    • mrdebugM Offline
      mrdebugM Offline
      mrdebug
      wrote on last edited by
      #2

      Does your program work in Linux?
      I have a problem with Android and Bluetooth. My application works in Linux but not in Android.
      See my recent post.

      Need programmers to hire?
      www.labcsp.com
      www.denisgottardello.it
      GMT+1
      Skype: mrdebug

      1 Reply Last reply
      0
      • X Offline
        X Offline
        X-Krys
        wrote on last edited by
        #3

        BLE (Bluetooth Low Energy) is not yet supported in Qt (work in progress in dev branch though).

        An alternative solution is to implement the bluetooth handling in android Java and use "JNI - Java Native Interface":http://en.wikipedia.org/wiki/Java_Native_Interface to interface it with your Qt code.
        JNI allows to make call between C++ and Java in both directions.

        Some resources to get started:

        • See doc of QtAndroidExtras module which defines some wrappers for JNI
        • Example of JNI use in Qt sources (look for JNI entry point => JNI_OnLoad function) :
          ** qtbase/src/plugins/platforms/android/androidjnimain.cpp
          ** qtmultimedia\src\plugins\android\src\qandroidmediaserviceplugin.cpp
        • Android BLE guide : https://developer.android.com/guide/topics/connectivity/bluetooth-le.html
        1 Reply Last reply
        0
        • M Offline
          M Offline
          mostefa
          wrote on last edited by
          #4

          Edit:
          [Solved] thanks to X-Krys

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved