Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Problem with qt bluetooth(qml type) [Solved]

    Mobile and Embedded
    3
    4
    1923
    Loading More Posts
    • 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
      mostefa last edited by

      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 Reply Quote 0
      • mrdebug
        mrdebug last edited by

        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 Reply Quote 0
        • X
          X-Krys last edited by

          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 Reply Quote 0
          • M
            mostefa last edited by

            Edit:
            [Solved] thanks to X-Krys

            1 Reply Last reply Reply Quote 0
            • First post
              Last post