×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    62

    Question Using data from Bluetooth stream in QML code

    I'm trying to use data received from a Bluetooth stream (coded in regular Qt C++) in my QML code (Qt Quick 3D), with the aim of using this data to rotate a 3D model. Is it possible to do this via bindings or similar? Thanks in advance.
    Last edited by Infms; 2011-10-13 at 15:36.

  2. #2
    Registered User
    Join Date
    May 2009
    Location
    Greece
    Posts
    191

    Re: Using data from Bluetooth stream in QML code

    Supposing that in your C++ you have a class that inherits from QObject:

    This could be your class.
    Code:
    #if QT_VERSION > 0x040603
    #include <qdeclarative.h>
    #endif
    
    class MyClass : public QObject
    {
         Q_OBJECT
         Q_PROPERTY(float x READ getX WRITE setX NOTIFY onXChanged)
         Q_PROPERTY(float y READ getY WRITE setY NOTIFY onYChanged)
         Q_PROPERTY(float z READ getZ WRITE setZ NOTIFY onZChanged)
    
    public:
         float getX();
         float getY();
         float getZ();
    
         void setX(float val){ x = val;}
         void setY(float val){ y = val;}
         void setZ(float val){ z = val;}
    
         static void registerQMLType()
         {
              qmlRegisterType<MyClass >("MyLibrary", 1, 0, "MyClass ");
         }
         //...the functions that will recieve data from bluetooth, set them to the local variables and every time 
         // any local variable changes you will emit the appropriate signal. Mandatory to achieve binding 
    
    signals:
        void onXChanged(float val);
        void onYChanged(float val);
        void onZChanged(float val);
    
    private:
         float x;
         float y; 
         float z;
    };
    In the main function before loading the qml file you will place the following code to register your C++ class to the QML:
    Code:
    MyClass::registerQMLType();
    Then in the qml file you want to use it :
    Code:
    import Qt 4.7
    import MyLibrary 1.0
    
    Rectangle
    {
       x:bluetoothReciever.x
       y:bluetoothReciever.y
       z:bluetoothReciever.z
    
       MyClass{
           id:bluetoothReciever
       }
    }
    This is a way to do what you want. Of course you need to add the bluetooth functions etc. but you get the idea.

  3. #3
    Registered User
    Join Date
    Feb 2011
    Posts
    62

    Re: Using data from Bluetooth stream in QML code

    This is exactly what I'm looking for, thanks favoritas!

Similar Threads

  1. Bluetooth data stream sending problem to PC
    By makwana89 in forum Bluetooth Technology
    Replies: 1
    Last Post: 2010-11-01, 15:58
  2. could i use this code to stream voice via bluetooth
    By fevos in forum Mobile Java Media (Graphics & Sounds)
    Replies: 0
    Last Post: 2008-11-24, 17:02
  3. Replies: 1
    Last Post: 2007-11-17, 01:04
  4. DATA STREAM from socket to bluetooth
    By mariobid in forum Mobile Java Networking & Messaging & Security
    Replies: 2
    Last Post: 2007-07-15, 06:17

Posting Permissions

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