I mean that if we using objectName() method that we must set this property to all instances of class in constructor or in other places. For example:
MyObject1()
{
// setObjectName("MyObject1");
// or
setObjectName(metaObject()->className());
}
or as you wrote:
Text {
id: mytext
objectName: "MyTextObject"
anchors.centerIn: parent
text: "Hello, World!"
}
But if we using className wrapper property than we may define this methods in our class declaration. And this is allow to us to making safe inheritance from MyObject1: for subclasses className() return actual className!
Q_PROPERTY(QString className READ className CONSTANT)
QString className()
{
return metaObject()->className();
}
and we can using objectName for other purposes, for example:
MyObject1 objA = new MyObject1();
objA.setObjectName("A");
MyObject1 objB = new MyObject1();
objB.setObjectName("B");
This is can be useful for debugging.
↧