[Qbs] Generating a c++ class with Q_OBJECT

Richard Weickelt richard at weickelt.de
Tue Aug 27 20:43:18 CEST 2019


> CppApplication {
>         name: "test"
>         cpp.includePaths: sourceDirectory
>         files: [
>             "main.cpp",
>         ]
>         Depends { name: "Qt"; submodules: ["core", "xml"] }
>         Depends { name: "kdsoap" }
>         Rule {
>             multiplex: true
>             Artifact { filePath: "wsdl.cpp"; fileTags: "cpp" }
>             Artifact { filePath: "wsdl.h"; fileTags: "cpp" }
>             prepare: {
>                 var file = product.sourceDirectory +
> "/wsdl/WsAnnuaire.wsdl";
>                 var cmd = new Command("kdwsdl2cpp", ["-both", "wsdl",
> file]);
>                 cmd.description = "generating " + outputs;
>                 cmd.workingDirectory = product.buildDirectory;
>                 return cmd;
>             }
>         }
>     }
> 
> Adding the second artifact makes qbs call moc on the wsdl.h and generates
> the qt.headers/wsdl.moc file.
> But how can I add this file to the link?

What do you mean by "link"? That the resulting .cpp file is compiled and
linked into your application? AFAIK, this should happen automatically. But
your rule above does not look kosher to me:

1. Your rule should specify a filetag as input. That might be "wsdl".
Otherwise Qbs will not (re-)run the rule upon changes in the wsdl file.

2. Consider to add a FileTagger for "wsdl" files or at least, put the wsdl
file into a group item and assign the "wsdl" filetag.

3. Why do you set multiplex true? Can the tool handle multiple wsdl input
files and creates one single large .h and .cpp file? Otherwise, consider to
set it to false (default) and generate one cpp+hpp file per wsdl file input.

4. I think you should use "hpp" as filetag for the wsdl header artifact.

5. Consider to add the output directory of the rule to cpp.includePaths if
you want to easily include them into your source files, for instance via
#include <wsdl.h>.

7. If you are going to use this generator in multiple products, consider to
write a module.
https://doc-snapshots.qt.io/qbs-master/custom-modules.html#custom-modules

The documentation about writing rules has recently been updated. Have a look
at:
https://doc-snapshots.qt.io/qbs-master/qml-qbslanguageitems-rule.html#a-complete-example

Does this maybe solve your problem?

Richard


More information about the Qbs mailing list