[Qt-qml] How plugin paths should work
Jyrki Hämäläinen
jyrki.hamalainen at nomovok.com
Mon Aug 9 10:09:34 CEST 2010
07.08.2010 16:15, Matthias Ettrich kirjoitti:
> On Friday 06 August 2010 09:14:44 ext Jyrki Hämäläinen wrote:
>
>> Hello everyone,
>>
>> We are trying to build a suite of applications with QML.
>> Some of the applications need to share C++-plugins.
>>
>> Also to enhance the structure of the application, some applications use
>> subfolders to group related qml-files into modules.
>>
>> The application structure would be like this
>>
>> /xxx/qmlapp/main.qml --> plugin_a, module1/mod1_a.qml, module1/mod1_b.qml
>> /xxx/qmlapp/qmldir
>> /xxx/qmlapp/module1/mod1_a.qml --> plugin_a
>> /xxx/qmlapp/module1/mod1_b.qml
>> /xxx/qmlapp/module1/qmldir
>>
>> /yyy/libs/libplugin_a.so
>>
>>
>> Where
>> main.qml uses 'import "module1"', to import qml files in subfolder module1.
>> main.qml ja qml-module located in the subfolder use the shared plugin.
>>
>> Also qmldir files have content as follows
>> /xxx/qmlapp/qmldir:
>> plugin plugin_a
>>
> That's the part which I don't get. There's no need to put "plugin plugin_a"
> into several qmldir files. Qt reads the module1/qmldir if you import module1.
>
> This might be the source of confusion.
>
> If removing this line does not help, please send a stripped down example to
> help us debugging your case.
>
>
Thanks Matthias,
You led me back to trail.
Quite obvious one, but for some reason we had failed to try / understand it.
I suppose we somehow got mixed with plugin paths and import paths.
The key is not to think in terms of plugins, but in terms of modules
that contain plugin(s).
Even though there is nothing more to examples, I'll make here a short
description how we managed to make things working. Just in case that
someone else happens to get confused - I hope I don't further confuse them.
So the file & usage hierachy is like this
/xxx/qmlapp/main.qml --> plugin_a, module1/mod1_a.qml, module1/mod1_b.qml
/xxx/qmlapp/module1/mod1_a.qml --> plugin_a
/xxx/qmlapp/module1/mod1_b.qml
/xxx/qmlapp/module1/qmldir
/yyy/my/shared/module/libplugin_a.so
/yyy/my/shared/module/qmldir
QML files that use the plugin import the shared module
main.qml:
----
import my.shared.module 1.0
import "module1" 1.0
----
module1/mod1_a.qml:
----
import my.shared.module 1.0
----
qmldir-file in internal module declares only what components are included in the module itself.
/xxx/qmlapp/module1/qmldir:
----
ItemA mod1_a.qml
ItemB mod1_b.qml
----
qmldir-file is needed also in the shared moduleto declare what components are included in the module.
/yyy/my/shared/module/qmldir:
----
plugin plugin_a
----
And finally we are able to run the application:
qmlviewer -I /yyy /xxx/qmlapp/main.qml
Thanks again, you saved my day.
BR,
Jyrki
ps.
The problem (as I understand it and the actual technical background may be somewhat different) was that we tried to use pluginpath to tell where plugins are located and then force QT to load the plugins by declaring the existence of them in the qmldir-files in the modules that use the plugin.
This led QT to believe that the plugin should be initialized under wrong modules "namespace" and moreover under multiple modules "namespaces".
This again confused parser for some reason.
Funny thing in here is that the parser does not seem to get confused, if each module actually contains a separate copy of the plugin file. Not that it really matters, as it is obviously a very wrong way to use such a plugin.
More information about the Qt-qml
mailing list