QML loaded from plugin cannot reference local types
we have code that is located in a C++ plugin (actually, a QML resource which is registered as a type via Plugin::registerTypes) which dynamically loads other QML, using a QtQuick.Loader. Lets call the registered type DynaLoader. The application which uses DynaLoader will pass in a string like "Bla.qml".
Now it turns out that components which themselves reference other locally defined QML types (i.e., types defined in QML files that are located alongside the initially loaded one) cannot be loaded, because the referenced type is not visible. For example, let Bla.qml be:
where AnotherBla.qml is located right alongside Bla.qml. Now, when at runtime we say
@DynaLoader.show = "Bla.qml"@
we get a message "AnotherBla is not a type".
I have to mention that all QML files (both in the plugin and in the application) are stored as resources.
Just a quick check. Hope it AnotherBla.qml.. 'A' in file name is capital letter. Are you able to load the AnotherBla.qml directly ? i.e not through Bla.qml.
sure I can load it. QtCreator sees it, too. It is only when Bla is loaded dynamically (through code residing in a plugin, as I said) that suddenly AnotherBla cannot be resolved.
ok, I've found something like a solution. The QML references I pass to the Loader must be relative to the root of the project. If that is the case, everything works. So simply saying
@DynaLoader.show = "/Bla.qml"@
causes Bla.qml and all nested components to be resolved correctly