On 26/11/2019 08:56, Ulf Hermann wrote:
We have some code that evaluates JS in custom QQmlContexts with certain
"magic" context properties set (sort of like the "index" or "modelData"
context properties in delegates like Repeater.delegate).
Will something similar still be possible?
You should rephrase that as required properties on actual objects. Then
the magic won't work anymore and you'll have to look up the properties
by ID of the object, but that is a good thing. It will improve
re-usability of your components.
Lookup by ID? You mean set the object name like you did in your example in your talk at QtWS? I protested then, and I will protest now again. Don't. Really: don't. If you are talking about re-usability and maintainability of your code elsewhere, then advocating this practice is really wrong. You need to layer your QML on top of an API provided by C++, not poke into your QML from C++.

We're also changing the way views and delegate work. If you want to use
the "index" in a Repeater's delegate you'll have to declare that in QML
3, using a required property:

Repeater {
      model: 10

      Text {
          required property int index
          text: "item " + index
      }
}

I really, really dislike this change. It looks even more like magic than what we have today. By all means deprecate/get rid off looking up without using `model.` in front of index, but what you write there really looks like magic. It is totally unclear who is setting a property (required or not) if you just declare it. This introduces more magic instead of less, and would IMO lead to more knowledge required in on the C++ side about the QML side of the application, where I just argued above that that leads to bad practice.


André



_______________________________________________
Development mailing list
Development@qt-project.org
https://lists.qt-project.org/listinfo/development
_______________________________________________
Development mailing list
Development@qt-project.org
https://lists.qt-project.org/listinfo/development

Reply via email to