[Interest] How to set a QJSValue with functions as a context property in QQmlContext?

Christian Kandeler christian.kandeler at qt.io
Thu Apr 16 11:31:33 CEST 2020


On Wed, 15 Apr 2020 17:33:55 +0200
Richard Weickelt <richard at weickelt.de> wrote:

> It is mostly about plumbing. But there is a little bit more. How much do you
> know about Qbs? The user does usually not write .js files, but .qbs files
> which look almost like QML. See
> https://doc.qt.io/qbs/language-introduction.html for examples. Those .qbs
> files cannot be loaded/evaluated directly by the QML engine. They need to be
> evaluated in steps and we follow a lazy evaluation approach. We analyse the
> structure first, then start to evaluate certain properties, for instance the
> "name" and "condition" property of a product item. On the RHS of these
> properties, the user might access other properties of the product or some
> other special items like "project". To do so, we intercept property read
> access. If the code under current evaluation accesses a property that has
> not been evaluated yet, we start evaluation now. This way we can:

This isn't quite how it works. At project resolve time, everything in the declarative part gets evaluated and stored somewhere for later retrieval (i.e. there is no delayed evaluation for normal properties).
The on-demand access mechanism kicks in later, when JS code in e.g. rule scripts accesses properties of JS objects that the C++ side has injected into the context. These objects are backed by a QScriptClass, and that's what is currently not possible with QtQml, as far as I understand. 


Christian


More information about the Interest mailing list