[QBS] Qt Plugin with QBS

Joerg Bornemann joerg.bornemann at theqtcompany.com
Mon Mar 16 15:57:42 CET 2015

On 16-Mar-15 13:12, at-2500 wrote:

> I am trying to set up a project using the Qt Plugin System.

The basic setup to create a Qt plugin is
   - create a product of type "dynamiclibrary"
   - add a JSON file and tag it with "qt_plugin_metadata"

> The project consists of multiple binaries, one dynamic library that defines the Q_INTERFACE (LIB) and multiple plugins (PLUGIN) implementing this interface. To have common unit tests for all plugins, I have a gtest-based binary that loads and tests the plugins via their interface. This binary should only get linked to LIB, not to PLUGINS, which is why I removed the „dynamiclibrary“ tag, and added a new tag, „plugin“ for PLUGINS. Now, of course, my plugin will not be build because there is no rule cpp,hpp - plugin. Is there an easy way to call the prepare script of the cpp rules that would be active for a dynamic library? Something like prepare: cpp.compiler.prepare? Or is there a better way to achieve what I want?

This use case is independent from Qt plugins.
Unfortunately there's currently not a good way to call the compiler's 
prepare script again. See also QBS-5.

What you can do instead is something like this

DynamicLibrary {
     name: "PLUGIN1"
     Depends {name: „cpp“}
     Depends {name: „LIB“}
     files: [...all cpp files for building the plugin...]

Product {
     name: "PLUGIN1_LINK"
     type: ["plugin_link"]
     Depends {name: „PLUGIN1“}
     // Rule to create the symlink for a plugin.
     // Use inheritance to avoid code duplication.

And then let plugintester depend on the PLUGIN*_LINK products.



More information about the Qbs mailing list