Hi all,
I'm trying to expose a class DoubleVector2D which is a Q_GADGET to qml. 
That class looks like this:
class DoubleVector2D
{
Q_GADGET
Q_PROPERTY(double x READ x WRITE setX)
Q_PROPERTY(double y READ y WRITE setY)
public:
DoubleVector2D() {}
DoubleVector2D(double x, double y) : m_x(x), m_y(y) {}
double x() const{ return m_x; }
double y() const { return m_y; }
void setX(double x) { m_x = x; }
void setY(double y) { m_y = y; }
private:
double m_x = 0.0;
double m_y = 0.0;
};
In my main.cpp I register it using 
qRegisterMetaType<DoubleVector2D>("DoubleVector2D");
In a seperate class which is QObject derived I have a function which returns 
such a DoubleVector2D.
Calling that function in my qml file returns the DoubleVector2D, so the class 
works with qml in principal.
However I also need/want to create objects of that class in my qml/js code.
I saw that QtPositioning is using Q_GADGET in the same way for example to 
expose QGeoCoordinate to qml.
There I can write QtPositioning.coordinate() and create an object of that 
class. I examined the source of QtPositioning, however I could not find out how 
this is done. qmlRegisterType() obiously does not work, as it is used to 
register QObject derived classes.
What am I missing here?

Cheers
Immanuel


_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to