<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <!-- module.qdoc --> <title>Module QML Type | Qbs Manual</title> <link rel="stylesheet" type="text/css" href="style/offline-simple.css" /> <script type="text/javascript"> document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css"); // loading style sheet breaks anchors that were jumped to before // so force jumping to anchor again setTimeout(function() { var anchor = location.hash; // need to jump to different anchor first (e.g. none) location.hash = "#"; setTimeout(function() { location.hash = anchor; }, 0); }, 0); </script> </head> <body> <div class="header" id="qtdocheader"> <div class="main"> <div class="main-rounded"> <div class="navigationbar"> <table><tr> <td ><a href="index.html">Qbs Manual</a></td></tr></table><table class="buildversion"><tr> <td id="buildversion" width="100%" align="right">Qbs 1.12.2</td> </tr></table> </div> </div> <div class="content"> <div class="line"> <div class="content mainContent"> <link rel="prev" href="qml-qbslanguageitems-group.html" /> <link rel="next" href="qml-qbslanguageitems-parameter.html" /> <p class="naviNextPrevious headerNavi"> <a class="prevPage" href="qml-qbslanguageitems-group.html">Group</a> <span class="naviSeparator"> ◦ </span> <a class="nextPage" href="qml-qbslanguageitems-parameter.html">Parameter</a> </p><p/> <div class="sidebar"> <div class="toc"> <h3><a name="toc">Contents</a></h3> <ul> <li class="level1"><a href="#properties">Properties</a></li> <li class="level1"><a href="#details">Detailed Description</a></li> <li class="level2"><a href="#special-property-values">Special Property Values</a></li> <li class="level2"><a href="#dependency-parameters">Dependency Parameters</a></li> </ul> </div> <div class="sidebar-content" id="sidebar-content"></div></div> <h1 class="title">Module QML Type</h1> <span class="subtitle"></span> <!-- $$$Module-brief --> <p>Represents a collection of properties and items that can be loaded into a product. <a href="#details">More...</a></p> <!-- @@@Module --> <div class="table"><table class="alignedsummary"> <tr><td class="memItemLeft rightAlign topAlign"> Import Statement:</td><td class="memItemRight bottomAlign"> import QbsLanguageItems .</td></tr></table></div><ul> <li><a href="qml-qbslanguageitems-module-members.html">List of all members, including inherited members</a></li> </ul> <a name="properties"></a> <h2 id="properties">Properties</h2> <ul> <li class="fn"><b><b><a href="qml-qbslanguageitems-module.html#additionalProductTypes-prop">additionalProductTypes</a></b></b> : stringList</li> <li class="fn"><b><b><a href="qml-qbslanguageitems-module.html#condition-prop">condition</a></b></b> : bool</li> <li class="fn"><b><b><a href="qml-qbslanguageitems-module.html#present-prop">present</a></b></b> : bool</li> <li class="fn"><b><b><a href="qml-qbslanguageitems-module.html#priority-prop">priority</a></b></b> : int</li> <li class="fn"><b><b><a href="qml-qbslanguageitems-module.html#setupBuildEnvironment-prop">setupBuildEnvironment</a></b></b> : script</li> <li class="fn"><b><b><a href="qml-qbslanguageitems-module.html#setupRunEnvironment-prop">setupRunEnvironment</a></b></b> : script</li> <li class="fn"><b><b><a href="qml-qbslanguageitems-module.html#validate-prop">validate</a></b></b> : script</li> <li class="fn"><b><b><a href="qml-qbslanguageitems-module.html#version-prop">version</a></b></b> : string</li> </ul> <!-- $$$Module-description --> <a name="details"></a> <h2 id="details">Detailed Description</h2> <p>A Module item is a collection of properties and language items that are used for building a product if the product has a <a href="qml-qbslanguageitems-depends.html">dependency</a> on the module. The following (somewhat artificial) module pre-processes text files by removing certain characters from them. The module's name is <code>txt_processor</code>.</p> <pre class="cpp"> import qbs import qbs<span class="operator">.</span>FileInfo import qbs<span class="operator">.</span>TextFile Module { property stringList unwantedCharacters: <span class="operator">[</span><span class="operator">]</span> FileTagger { patterns: <span class="operator">[</span><span class="string">"*.raw"</span><span class="operator">]</span> fileTags: <span class="operator">[</span><span class="string">"raw-txt"</span><span class="operator">]</span> } Rule { inputs: <span class="operator">[</span><span class="string">"raw-txt"</span><span class="operator">]</span> Artifact { filePath: FileInfo<span class="operator">.</span>relativePath(input<span class="operator">.</span>filePath<span class="operator">,</span> product<span class="operator">.</span>sourceDirectory) <span class="operator">+</span> <span class="string">"/"</span> <span class="operator">+</span> input<span class="operator">.</span>fileName <span class="operator">+</span> <span class="string">".processed"</span> fileTags: <span class="operator">[</span><span class="string">"processed-txt"</span><span class="operator">]</span> } prepare: { var cmd <span class="operator">=</span> <span class="keyword">new</span> JavaScriptCommand(); cmd<span class="operator">.</span>description <span class="operator">=</span> <span class="string">"Processing "</span> <span class="operator">+</span> input<span class="operator">.</span>fileName; cmd<span class="operator">.</span>sourceCode <span class="operator">=</span> function() { var inFile <span class="operator">=</span> <span class="keyword">new</span> TextFile(input<span class="operator">.</span>filePath<span class="operator">,</span> TextFile<span class="operator">.</span>ReadOnly); var content <span class="operator">=</span> inFile<span class="operator">.</span>readAll(); inFile<span class="operator">.</span>close(); var unwantedChars <span class="operator">=</span> product<span class="operator">.</span>txt_processor<span class="operator">.</span>unwantedCharacters; <span class="keyword">for</span> (var c in unwantedChars) content <span class="operator">=</span> content<span class="operator">.</span>replace(unwantedChars<span class="operator">[</span>c<span class="operator">]</span><span class="operator">,</span> <span class="string">""</span>); var outFile <span class="operator">=</span> <span class="keyword">new</span> TextFile(output<span class="operator">.</span>filePath<span class="operator">,</span> TextFile<span class="operator">.</span>WriteOnly); outFile<span class="operator">.</span>write(content); outFile<span class="operator">.</span>close(); }; <span class="keyword">return</span> cmd; } } } </pre> <p>And this is how a <a href="qml-qbslanguageitems-product.html">Product</a> would use the module:</p> <pre class="cpp"> Product { type: <span class="string">"processed-txt"</span> Depends { name: <span class="string">"txt_processor"</span> } txt_processor<span class="operator">.</span>unwantedCharacters: <span class="operator">[</span><span class="string">"\r"</span><span class="operator">]</span> files: <span class="operator">[</span> <span class="string">"file1.raw"</span><span class="operator">,</span> <span class="string">"file2.raw"</span> <span class="operator">]</span> } </pre> <p>Of course, normally the pre-processed files would not be the target artifacts of the product, but rather serve as inputs to a different rule that will often come from a different module.</p> <p>For more information about how you make your own modules available to Qbs, see <a href="custom-modules.html">Custom Modules and Items</a>.</p> <a name="special-property-values"></a> <h2 id="special-property-values">Special Property Values</h2> <p>For every property defined in a module, Qbs provides the following special built-in values:</p> <ul> <li><a href="qml-qbslanguageitems-module.html#base">base</a></li> <li><a href="qml-qbslanguageitems-module.html#original">original</a></li> <li><a href="qml-qbslanguageitems-module.html#outer">outer</a></li> </ul> <a name="base"></a> <h3 ><code>base</code></h3> <p>This value is useful when making use of inheritance. It stands for the value of the respective property in the item one level up in the inheritance chain. For instance:</p> <pre class="cpp"> Product { <span class="comment">// defined in MyProduct.qbs</span> Depends { name: <span class="string">"mymodule"</span> } mymodule<span class="operator">.</span>someProperty: <span class="operator">[</span><span class="string">"value1"</span><span class="operator">]</span> } <span class="operator">-</span><span class="operator">-</span><span class="operator">-</span><span class="operator">-</span><span class="operator">-</span><span class="operator">-</span> some other file <span class="operator">-</span><span class="operator">-</span><span class="operator">-</span><span class="operator">-</span><span class="operator">-</span><span class="operator">-</span> MyProduct { mymodule<span class="operator">.</span>someProperty: base<span class="operator">.</span>concat(<span class="operator">[</span><span class="string">"value2"</span><span class="operator">]</span>) <span class="comment">// => ["value1", "value2"]</span> } </pre> <a name="original"></a> <h3 ><code>original</code></h3> <p>This is the value of the property in the module itself (possibly overridden from a profile or the command line). Use it to set a module property conditionally:</p> <pre class="cpp"> Module { <span class="comment">// This is mymodule</span> property string aProperty: <span class="string">"z"</span> } <span class="operator">-</span><span class="operator">-</span><span class="operator">-</span><span class="operator">-</span><span class="operator">-</span><span class="operator">-</span><span class="operator">-</span><span class="operator">-</span><span class="operator">-</span><span class="operator">-</span> Product { Depends { name: <span class="string">"mymodule"</span> } Depends { name: <span class="string">"myothermodule"</span> } mymodule<span class="operator">.</span>aProperty: myothermodule<span class="operator">.</span>anotherProperty <span class="operator">=</span><span class="operator">=</span><span class="operator">=</span> <span class="string">"x"</span> <span class="operator">?</span> <span class="string">"y"</span> : original <span class="comment">// => "y" if myothermodule.anotherProperty is "x", "z" otherwise</span> </pre> <a name="outer"></a> <h3 ><code>outer</code></h3> <p>This value is used in nested items, where it refers to the value of the respective property in the surrounding item. It is only valid in <a href="qml-qbslanguageitems-group.html">Group</a> and <a href="commands.html#properties">Properties</a> items:</p> <pre class="cpp"> Product { Depends { name: <span class="string">"mymodule"</span> } mymodule<span class="operator">.</span>someProperty: <span class="operator">[</span><span class="string">"value1"</span><span class="operator">]</span> Group { name: <span class="string">"special files"</span> files: <span class="operator">[</span><span class="string">"somefile1"</span><span class="operator">,</span> <span class="string">"somefile2"</span><span class="operator">]</span> mymodule<span class="operator">.</span>someProperty: outer<span class="operator">.</span>concat(<span class="operator">[</span><span class="string">"value"</span><span class="operator">]</span>) <span class="comment">// => ["value1", "value2"]</span> } } </pre> <a name="dependency-parameters"></a> <h2 id="dependency-parameters">Dependency Parameters</h2> <p>Modules can declare dependency parameters. Those parameters can be set within <a href="qml-qbslanguageitems-depends.html">Depends</a> items. <a href="qml-qbslanguageitems-rule.html">Rules</a> of the module can read the parameters of dependencies and act accordingly.</p> <p>In the following example, the module <i>foo</i> declares the parameter <code>ignore</code>. A dependency to <code>bar</code> then sets the parameter <code>foo.ignore</code> to <code>true</code>. A rule in <code>foo</code> ignores all dependencies that have <code>foo.ignore</code> set to true.</p> <pre class="cpp"> Module { <span class="comment">// Definition of module 'foo'.</span> Parameter { property bool ignore } Rule { <span class="operator">.</span><span class="operator">.</span><span class="operator">.</span> prepare: { <span class="keyword">for</span> (i in product<span class="operator">.</span>dependencies) { var dep <span class="operator">=</span> product<span class="operator">.</span>dependencies<span class="operator">[</span>i<span class="operator">]</span>; <span class="keyword">if</span> (dep<span class="operator">.</span>foo<span class="operator">.</span>ignore) <span class="keyword">continue</span>; <span class="comment">// Do something with the dependency.</span> } } } <span class="operator">.</span><span class="operator">.</span><span class="operator">.</span> } <span class="operator">-</span><span class="operator">-</span><span class="operator">-</span><span class="operator">-</span><span class="operator">-</span><span class="operator">-</span><span class="operator">-</span><span class="operator">-</span><span class="operator">-</span><span class="operator">-</span> Product { Depends { name: <span class="string">"foo"</span> } Depends { name: <span class="string">"bar"</span>; foo<span class="operator">.</span>ignore: <span class="keyword">true</span> } } </pre> <!-- @@@Module --> <h2>Property Documentation</h2> <!-- $$$additionalProductTypes --> <div class="qmlitem"><div class="qmlproto"> <div class="table"><table class="qmlname"> <tr valign="top" class="odd" id="additionalProductTypes-prop"> <td class="tblQmlPropNode"><p> <a name="additionalProductTypes-prop"></a><span class="name">additionalProductTypes</span> : <span class="type">stringList</span></p></td></tr> </table></div> </div><div class="qmldoc"><p>A list of elements that will be added to the <a href="qml-qbslanguageitems-product.html#type-prop">type</a> property of a product that has a dependency on the module.</p> <p>Default: <code>[]</code></p> </div></div><!-- @@@additionalProductTypes --> <br/> <!-- $$$condition --> <div class="qmlitem"><div class="qmlproto"> <div class="table"><table class="qmlname"> <tr valign="top" class="odd" id="condition-prop"> <td class="tblQmlPropNode"><p> <a name="condition-prop"></a><span class="name">condition</span> : <span class="type">bool</span></p></td></tr> </table></div> </div><div class="qmldoc"><p>Whether the module is enabled. If this property is <code>false</code>, the surrounding Module item will not be considered in the module look-up.</p> <p>Default: <code>true</code></p> </div></div><!-- @@@condition --> <br/> <!-- $$$present --> <div class="qmlitem"><div class="qmlproto"> <div class="table"><table class="qmlname"> <tr valign="top" class="odd" id="present-prop"> <td class="tblQmlPropNode"><p> <a name="present-prop"></a><span class="qmlreadonly">[read-only] </span><span class="name">present</span> : <span class="type">bool</span></p></td></tr> </table></div> </div><div class="qmldoc"><p>This property is <code>false</code> if and only if the respective <a href="qml-qbslanguageitems-depends.html">Depends</a> item had its <a href="qml-qbslanguageitems-depends.html#required-prop">required</a> property set to <code>false</code> and the module was not found.</p> <p>Default: <code>true</code></p> </div></div><!-- @@@present --> <br/> <!-- $$$priority --> <div class="qmlitem"><div class="qmlproto"> <div class="table"><table class="qmlname"> <tr valign="top" class="odd" id="priority-prop"> <td class="tblQmlPropNode"><p> <a name="priority-prop"></a><span class="name">priority</span> : <span class="type">int</span></p></td></tr> </table></div> </div><div class="qmldoc"><p>The priority of this module instance. If there is more than one module instance available for a module name, the module with the highest priority is chosen.</p> <p>Default: 0</p> </div></div><!-- @@@priority --> <br/> <!-- $$$setupBuildEnvironment --> <div class="qmlitem"><div class="qmlproto"> <div class="table"><table class="qmlname"> <tr valign="top" class="odd" id="setupBuildEnvironment-prop"> <td class="tblQmlPropNode"><p> <a name="setupBuildEnvironment-prop"></a><span class="name">setupBuildEnvironment</span> : <span class="type">script</span></p></td></tr> </table></div> </div><div class="qmldoc"><p>A script for setting up the environment in which a product is built.</p> <p>The code in this script is treated as a function with the signature <code>function(project, product)</code>.</p> <p>Use the <a href="jsextension-environment.html">Environment</a> functions to alter the environment.</p> <p>The return value of this script is ignored.</p> <p>Default: Undefined</p> </div></div><!-- @@@setupBuildEnvironment --> <br/> <!-- $$$setupRunEnvironment --> <div class="qmlitem"><div class="qmlproto"> <div class="table"><table class="qmlname"> <tr valign="top" class="odd" id="setupRunEnvironment-prop"> <td class="tblQmlPropNode"><p> <a name="setupRunEnvironment-prop"></a><span class="name">setupRunEnvironment</span> : <span class="type">script</span></p></td></tr> </table></div> </div><div class="qmldoc"><p>A script for setting up the environment in which a product is run.</p> <p>The code in this script is treated as a function with the signature <code>function(project, product, config)</code>.</p> <p>The <code>config</code> parameter is a list of arbitrary strings that can be passed via the <a href="cli-run.html">run</a> command. The values supported by specific modules are listed in their respective documentation.</p> <p>Use the <a href="jsextension-environment.html">Environment</a> functions to alter the environment.</p> <p>The return value of this script is ignored.</p> <p>Default: Undefined</p> </div></div><!-- @@@setupRunEnvironment --> <br/> <!-- $$$validate --> <div class="qmlitem"><div class="qmlproto"> <div class="table"><table class="qmlname"> <tr valign="top" class="odd" id="validate-prop"> <td class="tblQmlPropNode"><p> <a name="validate-prop"></a><span class="name">validate</span> : <span class="type">script</span></p></td></tr> </table></div> </div><div class="qmldoc"><p>A script that is run after the module is loaded. It can be used to check property values and throw errors in unexpected cases. The return value is ignored.</p> <p>Default: Undefined</p> </div></div><!-- @@@validate --> <br/> <!-- $$$version --> <div class="qmlitem"><div class="qmlproto"> <div class="table"><table class="qmlname"> <tr valign="top" class="odd" id="version-prop"> <td class="tblQmlPropNode"><p> <a name="version-prop"></a><span class="name">version</span> : <span class="type">string</span></p></td></tr> </table></div> </div><div class="qmldoc"><p>The module's version. It consists of integer values separated by dots. You can check for specific values of this property in a <a href="qml-qbslanguageitems-depends.html">Depends</a> item.</p> </div></div><!-- @@@version --> <br/> <p class="naviNextPrevious footerNavi"> <a class="prevPage" href="qml-qbslanguageitems-group.html">Group</a> <span class="naviSeparator"> ◦ </span> <a class="nextPage" href="qml-qbslanguageitems-parameter.html">Parameter</a> </p> </div> </div> </div> </div> </div> <div class="footer"> <p> <acronym title="Copyright">©</acronym> 2019 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners.<br/> The documentation provided herein is licensed under the terms of the <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation License version 1.3</a> as published by the Free Software Foundation.<br/> Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners. </p> </div> </body> </html>