[Qbs] Can't find variable when using custom property

Christian Kandeler christian.kandeler at qt.io
Mon Feb 5 15:30:59 CET 2018

On Mon, 5 Feb 2018 14:43:57 +0100
Ola Røer Thorsen <ola at silentwings.no> wrote:

> I'm trying to do something like this:
> import qbs
> Rule {
>     property var myProperty: "test"
>     ...
>     outputArtifacts: {
>         console.warn(myProperty);
>     }
> }
> qbs can't find "myProperty" in the line trying to print it, saying
> ReferenceError: Can't find variable: myProperty

Right. Custom Rule properties are not collected for later use. Rule behavior is parameterized via properties of the respective module/product. 

> I've tried setting an id to the Rule item and using that, doesn't work. How
> can I access properties like this from within the Rule item? This does not
> seem to work well in general in qbs, except when defining a property in a
> "Product" item.

Custom properties are collected and made accessible in rules for the Product, Project and Modules items. 
For all other items, only the built-in properties are retrieved and acted upon according to their documented semantics.

> My use-case here is that in another Product I plan to do this:
> import "myrule.qbs" as MyRule
> ...
> MyRule { myProperty: "1" }
> MyRule { myProperty: "2" }
> MyRule { myProperty: "3" }
> MyRule { myProperty: "etc" }

Yes, I can see how that could be useful (see also the TODO item in CppModule.qbs). You might want to create a task in our bugtracker.


More information about the Qbs mailing list