Details
-
Suggestion
-
Resolution: Fixed
-
P2: Important
-
None
-
e9e315da0 (dev), 070303e40 (6.5)
Description
qmlContext(object) returns the internal context of an object which is a QQmlContext. When calling {{setContextproperty()} on such a context object, the user gets an error message "QQmlContext: Cannot set property on internal context".
1. It is not documented that objects have an internal context and that this context is not writable. Thus, the behavior is surprising. At least, it should be documented.
2. The returned context object is almost useless if it is read-only. There are situations where one needs to set context properties for specific objects. See below.
A { B { name: "blah" property string someProperty: "someValue" } B { name: "blub" RelatesTo { name: "blah" } // object blah is supposed to be attached as context property property string xz: blah.someProperty } }
In above example, the RelatesTo item makes the "blah" instance of B available in the "blub" instance. This is kind of similar to the Depends item in Qbs and happens after the Component::beginCreate() and before bindings are evaluated. But it is currently not possible because the "internal" context of each object is not writable and QObject::setProperty() has no effect.