0

I am currently porting my qmake files to Qbs. In my qmake setup I have created few defineTest in a single .pri file that is included by all other project files. These typicially just call one of the functions with a parameter (usually a project name) and that is it. Now with Qbs it seems to me that there could potentially be just a single file (docs even hint that) for all the projects.

However I would like to take my previous concept a bit further. Since I have the same structure for each project I could - in theory - iterate over the directories and for each directory name create a Product. I have a list of directories but now I do not know how to create a loop that would create a Product for each name in the list.

Does Qbs support loops? What is the syntax? And if not, what would be a workaround, perhaps importing a javascript module that has that logic? But how would I export it back in Qbs?

QMake does have loops but it lacks the file system capabilities and right now t seems that Qbs have file system capabilities but does not have loops the same qmake does...

Jake Petroules
  • 23,472
  • 35
  • 144
  • 225
Resurrection
  • 3,916
  • 2
  • 34
  • 56
  • qbs files are QML files. Recall that QML is a generic programming framework and has nothing to do with graphics - it's Qt Quick that adds graphic objects. Thus you can do anything that QML allows, i.e. creating objects on the fly using Loader and/or Component, etc. You can write JavaScript to drive it all too of course. – Kuba hasn't forgotten Monica Jun 04 '17 at 16:23
  • @KubaOber I looked more into it but I still cannot figure it out. The only place Qbs let me use javascript or QML is in property bindings. That would not be a problem but inside them `Product` item is unknown and any function I define outside of it as well. Simplest example would be: `Project { property var p: { Product {} } }` that complains that `Product` is unknown variable. While I can use explicitely `Product` in the `Project` scope I cannot use it in the loop or function. – Resurrection Jun 04 '17 at 18:52
  • A qbs file **is-a** QML file. That's pretty much the whole point of qbs's design. Perhaps you should look at some QML examples as they'll be more numerous. E.g. `{ property var p: { Product {} } }` is not valid QML. If you want to instantiate an object programmatically, you have to do it using a `Component` or a `Loader` object. Remember that QML objects are not plain JS objects and you can't instantiate them from JS using JS syntax. You instantiate them using QML syntax, or using QML objects that can do so. – Kuba hasn't forgotten Monica Jun 05 '17 at 05:37
  • Think of a qbs file as a QML file first, and qbs file second, and definitely look for QML examples. The only differences will be that with qbs you'll be instantiating qbs types, not Qt Quick types. But make sure you've read the entire core QML reference to understand what's available. Core QML is not big. – Kuba hasn't forgotten Monica Jun 05 '17 at 05:48
  • @KubaOber Thanks for the hints! I figured out how to do it in QML but sadly it cannot be used in Qbs. In order to dynamically instantiate an object I would need access to Qt QML type and that is unavailable in Qbs. I am contemplating generating the Qbs file but that kind of a defeats the purpose. :-) – Resurrection Jun 05 '17 at 20:13
  • Modify Qbs to add that type :) – Kuba hasn't forgotten Monica Jun 05 '17 at 20:15

0 Answers0