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.