[Qbs] Accessing overloaded properties

Christian Kandeler christian.kandeler at qt.io
Mon Jan 8 12:52:27 CET 2024


On 1/8/24 12:37, Jochen Becher via Qbs wrote:
> I havbe a question about qbs syntax. My qbs files look like this:
>
> MyProject.qbs:
>
> Project {
> 	property string installDir: { throw "installDir must be set" }
> }
>
> AProject.qbs:
>
> MyProject {
>      id: solution
>      installDir: "myfolder"
>
>      MyProject {
>          installDir: solution.installDir + "/mysubfolder"
>      }
> }
>
> My question is about"solution.installDir". Using "project.installDir"
> doesn't work. "outer.installDir" or "base.installDir" is also not
> allowed or not what I want.

What about "parent.installDir"?

> But I am not sure if defining "id" and using it in a subitem like in
> QML is really supported. It works and is sometimes but it is not
> documented in the qbs manual.

In hindsight, it was a mistake to support QML ids in qbs, because there 
are too many contexts in which they do not make sense due to the 
syntactic context not matching the semantic one (modules!).

My advice as to when to use them:

   - In Probes, because that's how the mechanism officially works.

   - In Depends items, if the dependee has an "unfortunate" name (e.g. 
with spaces) and you want to set properties on it.

   - Nowhere else.

In practice, Project items are probably safe, because there is no 
multiplexing of any kind involved.


Christian



More information about the Qbs mailing list