Must Q_PROPERTYs with user-defined C++ types be of pointer type?
-
Consider the following simple example:
namespace MyNamespace { class MyPoint { Q_OBJECT Q_PROPERTY(float x READ CONSTANT); ... }; class Circle { Q_OBJECT Q_PROPERTY(MyNamespace::MyPoint centre READ centre NOTIFY centreChanged); ... }; } Q_DECLARE_METATYPE(MyPoint);
An instance of
Circle
is set as a context property for some qml so it can be used:Rectangle { x: circleProperty.centre.x y: circleProperty.centre.y ... }
MyPoint
is registered usingqmlRegisterType<MyPoint>(...)
. However, this function only callsqRegisterMetaType
forMyPoint*
andQDeclarativeListProperty<MyPoint>
so when I run my app, I get qml errors saying it doesn't know about theMyNamespace::MyPoint
type.The errors go away if I explicitly use
qRegisterMetaType<MyPoint>("MyNamespace::MyPoint");
although now QtQuick won't read through thecircleProperty.centre
property access to getx
. If I printcircleProperty.centre
it saysQVariant(MyNamespace::MyPoint)
which is fine butcircleProperty.centre.x
is undefined.Given the behaviour of qmlRegisterType and the errors I see if I work around the behavior, it seems like what I'm trying to do with properties of C++ types without using pointers is not supported. Is that so?