Use variable in import statement?
-
wrote on 5 Dec 2017, 00:07 last edited by
Is there a way to do something like meta-meta data in pure qml?
import parent.someVariable
...where someVariable is declared in a parent file?
In some languages, there are meta tags which are swapped out with script/code before the file gets compiled. Wondering if QML has any provision for that.
Alternatively, is there a way to load a qml file, and then alter something in its scripting before it goes to the engine?
-
Accessing parent does not require any import. Parent is always available, for all components, so you can just use the parent property. Just make sure that at runtime it is available in the actual parent of your component.
I think that using File Selectors can also help you in your case.
-
wrote on 8 Dec 2017, 18:43 last edited by
Ok, thanks for the reply. I should not have put the "parent" reference in my question. I'm wondering if QML has any way of doing metadata. For instance literally typing something like this in code,
import someVariable
where someVariable is declared elsewhere, as a global.
-
No. Global variables are just global, there is no need to import them. For example if you declare root context property "engine", you can access engine properties from any QML file in your project, with no need for an import statement.
If you do want to have an explicit import, consider registering a QML singleton or adding a C++ component which is a singleton behind the scenes.
-
wrote on 10 Dec 2017, 07:07 last edited by
ok, thanks again. I'm asking about meta tags and meta data, not globals. probably qml doesn't have it.
1/5