[Interest] Qml plugin which registers at the same time C++ items and Qml files from resources.

Jérôme Godbout jerome at bodycad.com
Tue Jul 12 17:26:05 CEST 2016


Sorry I don't know the way to solve this but I can explain why it does not
work:
*qmlRegisterType()* require a *QObject** derivated type to work, since the
register type you provide is not that kind of object, it cannot work with a
.js file.

One thing I know that work is to add the whole resource module to the QQml
engine:
*my_qqml_engine_cpp_instance.addImportPath( "qrc:///MyCompany/MyModule" );*

This way everything from that module (if it have a proper qmldir inside the
resource is their and the proper C++ plugin module are found inside the
engine too) should work flawlessly without having to register every
component by hand.

This is not an answer to the question but it might help,
Jerome

On Tue, Jul 12, 2016 at 4:59 AM, Tomasz Olszak <olszak.tomasz at gmail.com>
wrote:

> Hi,
>
> Let's consider following use case:
>
> 1. Qml C++ plugin which registers C++ classes to Qml engine
> 2. It also has Qml files compiled in
>
> qmldir:
>
> module MyCompany.MyModule
>
> plugin MyModule
>
> classname MyModulePlugin
>
>
> qrc:
>
> :/MyCompany/MyModule/Item1.qml
>
> :/MyCompany/MyModule/Item2.qml
>
>
> In MyModulePlugin::registerTypes(...):
>
>
> // Register some C++ classes
>
> ...
>
> // Register Qml files from resources
>
> qmlRegisterType(QUrl("qrc:/MyCompany/MyModule/Item1.qml"), uri, 1, 0, "Item1");
>
> qmlRegisterType(QUrl("qrc:/MyCompany/MyModule/Item2.qml"), uri, 1, 0, "Item2");
>
>
> So as I understand above function corresponds to qmldir entry:
>
> Item1 1.0 Item1.qml
>
>
>
> Question:
>
>
> How to register javascript files using such approach. In qmldir it can be done like:
>
> JsFile 1.0 JsFile.js
>
>
> But following:
>
> qmlRegisterType(QUrl("qrc:/MyCompany/MyModule/JsFile.js"), uri, 1, 0, "JsFile");
>
>
> registers JsFile as attached property and I can't use functions from JsFile.js.
>
>
>
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160712/e0ee549e/attachment.html>


More information about the Interest mailing list