Qt Forum

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

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Qt5.2 beta bluetooth exams good working on android ?

    Mobile and Embedded
    8
    16
    6043
    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.
    • J
      jamesLee last edited by

      Are the bluetooth examples of Qt5.2 beta1-android(on the window7) worked good on the galaxy tab(android ver4.0.4) too?
      I just build->deploy->run the btscanner by qtCreator(API 10 or 15)..Any bluetooth devices are not scanned..
      The localDevice->isValid() is false continuous.
      What's mean the "◾Qt Bluetooth: supported on Linux with Bluez 4.x and Blackberry"?
      Android is based on linux kernel, right? I don't know what need anymore. Bluetooth protocol stack?
      who can help me?

      1 Reply Last reply Reply Quote 0
      • P
        peterlin82 last edited by

        I tried :
        QBluetoothLocalDevice bluetoothLocalDevice1;

        in ubuntu 12.04
        bluetoothLocalDevice1.isValid() is true

        in Nexux7(Android)
        bluetoothLocalDevice1.isValid() is false

        Qt bluetooth seemed to supports Linux and Blackberry only.

        1 Reply Last reply Reply Quote 0
        • L
          liangliang last edited by

          i made a demo form the Qt help ( Bluetooth Chat Example),and i use two phones ( android) to test them ,but they can not connect ,so i think maybe the qt bluetooth do not support android .

          1 Reply Last reply Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            Hi,

            Current state of bluetooth is given "here":http://blog.qt.digia.com/blog/2013/09/30/qt-5-2-alpha-available/

            And the relevant bug to follow is "QTBUG-33792":https://bugreports.qt-project.org/browse/QTBUG-33792

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply Reply Quote 0
            • X
              XelaG last edited by

              According to KDab, Bluetooth might be supported in Qt 5.3.
              "Qt Android":http://www.kdab.com/qt-on-android-episode-1/

              "Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - Martin Golding

              1 Reply Last reply Reply Quote 0
              • S
                s.frings74 last edited by

                I dont want to wait for Qt 5.3, therefore I found a way to access the Java Bluetooth API via JNI.

                http://stefanfrings.de/android_qt/index-en.html

                It seems that Qt 5.3 contains a very similar approach. The main difference seems to be that Qt 5.3 recieves data in a separate thread and signals reception with a signal. My class works with polling, the application has to check repeatedly, if something has been received.

                1 Reply Last reply Reply Quote 0
                • JKSH
                  JKSH Moderators last edited by

                  [quote author="s.frings74" date="1398153323"]I dont want to wait for Qt 5.3, therefore I found a way to access the Java Bluetooth API via JNI.

                  http://stefanfrings.de/android_bluetooth/index-en.html

                  It seems that Qt 5.3 contains a very similar approach. The main difference seems to be that Qt 5.3 recieves data in a separate thread and signals reception with a signal. My class works with polling, the application has to check repeatedly, if something has been received.
                  [/quote]Hi Steve, thank you for sharing your solution!

                  Note that you don't have to wait. The Qt 5.3 beta is already available: http://download.qt-project.org/development_releases/qt/5.3/5.3.0-beta/ (The Release Candidate will be out this coming Thursday)

                  Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                  1 Reply Last reply Reply Quote 0
                  • S
                    s.frings74 last edited by

                    Oops, so I wasted a weekend :-)
                    At least I learnt a bit about JNI.

                    1 Reply Last reply Reply Quote 0
                    • U
                      uusitalo last edited by

                      This is what im looking for but cant get it connect to arduino.
                      Im using QT 5.3 Beta

                      @W/System.err( 9490): java.io.IOException: read failed, socket might closed or timeout, read ret: -1
                      W/System.err( 9490): at android.bluetooth.BluetoothSocket.readAll(BluetoothSocket.java:569)
                      W/System.err( 9490): at android.bluetooth.BluetoothSocket.readInt(BluetoothSocket.java:580)
                      W/System.err( 9490): at android.bluetooth.BluetoothSocket.connect(BluetoothSocket.java:321)
                      W/System.err( 9490): at dalvik.system.NativeStart.run(Native Method)
                      E/Qt ( 9490): ../Mittari/androidrfcomm.cpp:33 (void AndroidRfComm::check(const char*)): Exception in BluetoothSocket.connect()
                      E/Qt ( 9490): ../Mittari/androidrfcomm.cpp:161 (void AndroidRfComm::connect(const QString&)): Cannot connect to the bluetooth device
                      D/Qt ( 9490): fontdatabases/basic/qbasicfontdatabase.cpp:238 (static QStringList QBasicFontDatabase::addTTFile(const QByteArray&, const QByteArray&)): FT_New_Face failed with index 0 : 90@

                      1 Reply Last reply Reply Quote 0
                      • S
                        s.frings74 last edited by

                        I would try to test the connection with a plain Java program. Then you know if there is an issue with the C++ part or a problem in the underlying Java interface.

                        I would also try to use another program first, for example "Bluetooth SPP" (the older 1.x version, version 2 runs unstable).

                        By the way: Why do you use my class with Qt 5.3? You dont need it!

                        1 Reply Last reply Reply Quote 0
                        • U
                          uusitalo last edited by

                          Because i dont know how to code but i need to make simple android <-> hc-06 bluetooth program that reads numbers from arduino and displays them and can send terminal commands to it.

                          I made one version with eclipse but it doesnt work on other phones than samsung, dont know why.

                          And i am thinking that qt is best language fir coding because its multiplatform.

                          I tried to study bluetooth coding from chat example but its just too complex

                          1 Reply Last reply Reply Quote 0
                          • S
                            s.frings74 last edited by

                            Yes, the bluetooth classes of Qt are a bit more difficult. The use asynchronous callbacks to indicate received data. Also openng a connection is a bit more difficult. You have to search the arduino first and then you have the object needed to open a connection.

                            Anyway,check first if you have the same connection problems in Java. Create a new project with an empty activity. then insert the following lines into the end of MainActivity.onCreate() method:

                            @
                            try {
                            BluetoothAdapter adapter=BluetoothAdapter.getDefaultAdapter();
                            Set<BluetoothDevice> pairedDevices=adapter.getBondedDevices();
                            Iterator<BluetoothDevice> iterator=pairedDevices.iterator();

                            while (iterator.hasNext()) {
                             BluetoothDevice device=iterator.next();
                             Log.w(this.getClass().getSimpleName(),"Found "+device.getAddress()+" = "+device.getName());
                             
                             // Check for my Ardunio either by address or name
                             // if device.getAddress().equals("20:13:11:15:16:08")) {
                             if (device.getName().equals("HC-06")) { 
                              BluetoothSocket socket=device.createRfcommSocketToServiceRecord(UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"));
                              socket.connect();
                              InputStream istream=socket.getInputStream();
                              OutputStream ostream=socket.getOutputStream();
                              ostream.write("whatever you want to send\n".getBytes());
                              ostream.flush(); // seems to be not neccessary
                            
                              Thread.sleep(1000);
                              int avail=istream.available();
                              Log.w(this.getClass().getSimpleName(),"Received "+avail+" bytes");
                              
                              BufferedReader br = new BufferedReader(new InputStreamReader(istream));
                              String s=br.readLine();
                              Log.w(this.getClass().getSimpleName(),"Received: "+s);
                             }
                            
                            }
                            

                            }
                            catch(Exception e) {
                            e.printStackTrace();
                            }
                            @

                            Are you sure that you entered the correct device address? Every Bluetooth module has its own unique address.

                            1 Reply Last reply Reply Quote 0
                            • S
                              s.frings74 last edited by

                              I found a bug in androidrfcomm.cpp:
                              @
                              if (address.compare(adr.toString(),Qt::CaseInsensitive)) {...}
                              @
                              Must be changed to
                              @
                              if (address.compare(adr.toString(),Qt::CaseInsensitive)==0) {...}
                              @

                              Otherwise it would attempt to connect to the first bluetooth devcie that is reachable. May that's your problem cause.

                              1 Reply Last reply Reply Quote 0
                              • U
                                uusitalo last edited by

                                i do have java version working, but i dont want to make my app with java its just too complicated.

                                but thats just what im trying to do and when i can do it in qt its easy to customise in my way

                                i made motorcycle speedometer with eclipse but i still have few issues with keeping bluetooth state when changing orientation

                                1 Reply Last reply Reply Quote 0
                                • S
                                  s.frings74 last edited by

                                  I just uploaded an improved version of the class.
                                  The isTimeout() function did not work as planned, and you can now connect by device address or name.
                                  I also added an example program.

                                  1 Reply Last reply Reply Quote 0
                                  • JKSH
                                    JKSH Moderators last edited by

                                    [quote author="s.frings74" date="1398174767"]Oops, so I wasted a weekend :-)
                                    At least I learnt a bit about JNI.[/quote]I don't think that's wasted -- learning more about your target platform is always useful. :)

                                    Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

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