Unsolved QML Plugin cannot find child qml items from compiled qrc
-
Hi all,
I'm working on a QML Plugin. It works fine when using regular QML files from the qml plugins dir. Now I want to use the qml resrouce compiler for faster qml start:
qtquick_compiler_add_resources(myplugin_qrc myplugin.qrc )
add to my plugin
add_library( ${PROJECT_NAME} SHARED ... ${myplugin_qrc})
And I can successfully load my first file
Loader { anchors.fill: parent source: "qrc:/qml/MyPlugin/MyPlugin.qml" }
But every other qml component that I use inside MyPlugin.qml (Like a Background.qml) fails to load because it then tries to look it up in the regular path.
qrc:/qml/MyPlugin/MyPlugin.qml:43:5: Type Background unavailable Loc: [qrc:/qml/MyPlugin/MyPlugin.qml:43] file:///C:/Qt/5.14.2/msvc2017_64/qml/ScreenPlay/MyPlugin/Background.qml: No such file or directory Loc: [file:///C:/Qt/5.14.2/msvc2017_64/qml/ScreenPlay/MyPlugin/Background.qml:-1]
What I tried:
Add Q_INIT_RESOURCE(MyPluginResource); to my MyPlugin_plugin.cpp registerTypes Add qmlDir to my qrc file. Add relative paths to my qmlDir entries: Background 1.0 qml/MyPlugin/Background.qml
From my understanding, when using qtquick_compiler_add_resources it compiles the qml files to c++ and adds them to my dll. So I'm not sure if
engine->addImportPath(uri);
would work here.
Someone else had a similar problem, but he used the same name for the resource file. My resource file names of my app and my plugins are different. https://forum.qt.io/topic/82509/problem-using-a-qml-plugin-from-application/2
Any ideas?