Organising a QML project with a plugin and an app
-
Hi guys!
I had a question about the organisation of my project with QML (I use Qt 5.3.2).
I have a set of standard/generic controls that I want to use to build an actual application.
What I wanted to do is to have a specific QML plugin with all my controls, and then use that plugin on my application.
Does that make sense? I have a hard time finding out ways of organising a QML project online.So I tried to implement this system, and I end up with this: my main project is a template subdirs project. It has 2 children:
app
andcontrols
.
controls
is the QML plugin (template lib), andapp
is the application itself (template app).
In thecontrols
project, I have aqmldir
file to register my plugin and my QML files. All the resources of my plugin (QML files and icons) are in the QRC ofcontrols
. The install step only copy the dynamic library (which I think should contain the QRC) and theqmldir
. I used a QRC because I'd really like to only have a dynamic library and not have to publish all the QML sources.
In theapp
project, I also have a QRC with the actual views of my application. This project has no direct link with thecontrols
project, since the latter generated a dynamic library.
The entire thing look like this:root/ | +-- root.pro | +-- app/ | | | +-- app.pro | | | +-- app.qrc/ | | | +-- main.qml | +-- controls/ | +-- controls.pro | +-- qmldir | +-- controls.qrc/ | +-- QML + icons...
When I run my application, I specify the
QML2_IMPORT_PATH
to the path where I installed thecontrols
plugin so that I canimport my.plugin.controls 1.0
in my views.
But, the issue is that, although my application find the plugin, it can not load the QML elements because the files are not found.
I tried to useQ_INIT_RESOURCE(controls)
in the app, but it doesn't work either. I always end up with my QML files being not found.
How can I fix that? Is this an idiomatic way of organising a QML project in the first place?Thanks a lot!