[Qt-qml] Loading QML plugin from the resource system

Kai Koehne kai.koehne at nokia.com
Thu Jan 20 08:45:21 CET 2011


On 1/19/2011 8:00 PM, ext Sampo Savola wrote:
>
> Hello
>
> I have an Qt application where I have resource system in use  and I
> have added my main.qml to it.
>
> In my main.cpp I load main.qml like this:
>
> QDeclarativeView view;
> view.setSource(QUrl("qrc:/main.qml"));
>
> This works OK, but I would like to load QML plugin from my main.qml file.
> Is it possible to include QML plugin in Qt's resource system?
> If it is possible how should it be loaded from .qml file that is in
> Qt's resource system and how QML plugin should be added to Qt Resource
> system?

You might be able to achieve this by calling 
QDeclarativeEngine::addImportPath(). E.g. if your import statement is 
'import MyPlugin 1.0', you can try to include your qmldir file as 
qrc:/imports/MyPlugin/qmldir', and call 
engine->addImportPath("qrc:/imports") before loading the main file in 
the engine. Obviously the .qml files that make up the plugin should then 
be also available under qrc:/imports/MyPlugin . I haven't tried that 
myself, though.

Anyhow, may I ask why you want to put it in the resources in the first 
place? The idea of a QML plugin is that it contains stuff you want to 
share between apps, and compiling it into the resource system seems to 
somewhat contradict this.

Regards

Kai

> Thanks
> Sampo
>
> _______________________________________________
> Qt-qml mailing list
> Qt-qml at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-qml


-- 
Kai Koehne
Software Engineer
Nokia, Qt Development Frameworks

Nokia gate5 GmbH
Firmensitz: Invalidenstr. 117, 10115 Berlin, Germany
Registergericht: Amtsgericht Charlottenburg, Berlin: HRB 106443 B
Umsatzsteueridentifikationsnummer: DE 812 845 193
Geschäftsführer: Dr. Michael Halbherr, Karim Tähtivuori


More information about the Qt-qml mailing list