[QBS] Project configuration from within qbs profile

Richard Weickelt richard at weickelt.de
Mon Jul 21 09:24:29 CEST 2014

> Ok, I've tried to create a module "MyModule" and access one of its
> properties, but failed:
> ---- mymodule.qbs ----
>     import qbs.base 1.0
>     Module
>     {
>         name: "MyModule"
>         property string myProperty
>     }
> ---- myproject.qbs ----
>     import qbs.base 1.0
>     import "mymodule.qbs" as MyModule
>     Product {
>         // ...
>         Depends { name: "MyModule" }
>         property string productProperty: MyModule.myProperty
>         // ...
>     }
> This results in : myproject.qbs:4:1 Product dependency 'MyModule' not found.
> I've also tried to create a subfolder and load the module from there as it
> has been advised in the QML documentation, without luck. Maybe I make a
> general mistake here. These are my first steps with qbs and QML so I'm not
> too familiar with the module concept, yet.

It took me a while, but after looking at some qbs projects in the www, I got
my head around this. Please correct me if I am wrong.

Qbs modules are not a QML language feature, so the import statement is
useless here. Instead, they seem to be loaded via some magic background
functionality. For custom modules in a project, one is supposed to create a
subfolder with the following layout:

+--subfolder e.g. 'qbs'
|  +--'modules' folder
|     +--folder with module-name, e.g. 'myModule'
|        (name is important here)
|        +--.qbs file containing the module definition
|           (name does not matter)
+--.qbs project file which defines qbsSearchPaths : "qbs"

In the project file one would now write 'Depends { name: "myModule" }' to
load the module. Then one can access its properties as expected.

The documentation mentions 'Depends' and 'qbsSearchPaths', but the missing
link was the folder layout and naming.

> I have a question regarding project configuration. A qbs project defines a
> property "myProperty". I can of course set the property in the qbs file
> itself and I can set the property on command line via:
>   qbs build myproject.qbs project.myProperty:bla
> Would it also be possible to set this property in a qbs profile? That is
> because I have multiple projects which should be compiled with the same
> value for "myProperty".
> After some investigation I guess that project-specific settings are not
> supposed to go into the profile. Should I create a module for that? Is it
> possible to set a module's properties in a qbs profile?

Once I got modules working, the rest was easy. Module properties can be set
in a qbs profile and then accessed from within the qbs project file.


More information about the Qbs mailing list