Get hold of the module that imported us in QML/Qbs

62 Views Asked by At

As a beginner in Qbs/QML I want to get information about what instance that imported our module. For example, given this project:

.
├── a
│   └── imported.qbs
└── b
    └── main.qbs

with a/imported.qbs like this:

Product{
    name:{
        console.info("I was imported from" + XXX);
        return "imported"
    }
}

and b/main.qbs like this:

import "../a/imported.qbs" as Imported
Imported {}

When I run main.qbs, how could I get the instance that imported imported.qbs (main.qbs)?

Or in other words, what should I susbstitute for XXX to print main.qbs.

2

There are 2 best solutions below

4
Christian Kandeler On

I don't think you can get the file name of the instantiating item, nor should it be relevant.

0
Mr. Developerdude On

I solved this myself, and thought maybe someone else might have use from my findings. I solved it like this:

In b/main.qbs I created property name2 & path2 to hold the local name & path like so:

import "../a/imported.qbs" as Imported
Imported {
    property string path2:path
    property string name2:name
}

and in a/imported.qbs I use the properties like this:

Product{
    name:{
        console.info("I was imported from" + name2 + " (" + path2 + ")");
        return "imported"
    }
}