[Qbs] Accessing properties from a parent project

Richard Weickelt richard at weickelt.de
Thu Jul 10 23:38:32 CEST 2025


On 7/10/25 16:59, Christian Kandeler via Qbs wrote:
> On 7/10/25 1:16 PM, Richard Weickelt wrote:
>> > Qbs flattens nested and merges referenced project items during the 
>> evaluation process.
> 
> That's news to me ;)
> 

Well, my wording might have been not exact and misleading, sorry, but yet 
Qbs manipulates project items which effectively results in a flattened 
structure of property values in project items. It's not the way my wording 
may have suggested, but much more complicated. I am referring to the calls 
to copyProperties() in ProductsCollector, especially this one: 
https://code.qt.io/cgit/qbs/qbs.git/tree/src/lib/corelib/loader/productscollector.cpp#n441 
which implements inheritance of project properties.

Qbs physically copies properties from outer project items into inner project 
items and from upper project items into sub project items before evaluation. 
The problem Jochen describes happens because Qbs copies mySetting from 
SupportProject into MyApp.

In SupportProject "parent" resolves to TestProject.
In MyApp "parent" resolves to SupportProject where we copy the value from.

To fix the relationship, one could change line 
https://code.qt.io/cgit/qbs/qbs.git/tree/src/lib/corelib/loader/productscollector.cpp#n451 
to

     Item::addChild(projectItem->parent()->parent(), loadedItem);

probably with some additional checking (projectItem->parent() may not have a 
parent). projectItem is the SubProject item and projectItem->parent() is 
SupportProject where we copy the properties from, so 
projectItem->parent()->parent() is the intended parent (TestProject). But 
whether that is the right thing to do, I leave up to Christian.

Cheers
Richard


More information about the Qbs mailing list