Greetings, during last years of development with QML I always wondered how to solve certain software engineering problems.
First, defining private properties: I have seen sometimes doing: Item { property int publicProp: 40 + state.privateProp QtObject { id: state property int privateProp: 2 } } which seems a rather clever workaround, except for some reason it does not work with QtObject itself (error: Cannot assign to non-existent default property): QtObject { property int publicProp: 40 + state.privateProp QtObject { id: state property int privateProp: 2 } } it is possible to do: QtObject { property int publicProp: 40 + _.privateProp property QtObject _: QtObject { property int privateProp: 2 } } but it exposes the private QtObject so it kind of defeats its purpose. Then, another rather important thing is the overriding (of properties and methods) in derived components, e.g.: //BaseObject.qml Item { readonly property bool canFly: false function foo() { console.log('foo()') } } //ExtendedObject.qml BaseObject { canFly: true // Invalid property assignment: "canFly" is a read-only property function foo() { console.log('foo() overridden') } } the property-overriding pattern would work only if the property is writable, which is not intended. the method-overriding pattern doesn't give any error and seems to work also when casting an instance x of ExtendedObject with 'as', e.g.: (x as BaseObject).foo() so I wonder if this is legal and it would be the preferred way for overriding things (behavior) in derived components.
_______________________________________________ Interest mailing list Interest@qt-project.org https://lists.qt-project.org/listinfo/interest