[Qt-qml] Loading QML plugin from the resource system
Sampo Savola
samposav at mail.student.oulu.fi
Thu Jan 20 10:03:22 CET 2011
Hi
And thanks for the reply.
Quoting Kai Koehne <kai.koehne at nokia.com>:
> 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.
The reason I wanted to use QML plugin in the first place was that I
want to use my existing quite complex QWidget in my QML application
with QGraphicsProxyWidget. And based on the documentation and
examples, the recommended way to use QWidget's in QML applications is
to make them as QML plugins.
By including the plugin in Qt's resource system would make deploying
the plugin with the application a bit easier.
//Sampo
> Regards
>
> Kai
>
More information about the Qt-qml
mailing list