Quantcast
Channel: Jobs
Viewing all articles
Browse latest Browse all 18427

Load shared library with QML files in resource file

$
0
0
Hi, I have the following use-case: I want to protect the QML code of a dynamic library and thus add the QML files to a qrc file. The library is created by compiling the resource file into the library which is a QDeclarativeExtensionPlugin, so it is also possible to mix C++ code and QML code in the library. From my application, I then load the library by importing the plugin. In order the QML components are found, I also added the qmldir file into the qrc file of the library. If i import the plugin now from the application, it only works if a QML component of the library is not created in the main.qml file. When I load it dynamically either with Qt.createComponent() or the Loader element it works fine, but if the component is in the main.qml file the error output is file::/qml/PluginApplication/main.qml: TestItem is not a type So to clarify, here is an overview what works and what not: // main.qml:   import QtQuick 1.1 import MyPlugin 1.0   Item {   id: window     // does NOT work, TestItem is a QML component in the dynamic library   TestItem {}     Component.onCompleted: {     // this works     var comp = Qt.createComponent("qrc:/plugins/MyPlugin/TestItem.qml")     var obj = comp.createObject(window)   }     // this also works   Loader {     id: loader     x: 100     y: 100   }   MouseArea {     anchors.fill: parent     onClicked: {       // the DynamicallyLoadedTestItem.qml contains a TestItem as its root element       loader.source = "DynamicallyLoadedTestItem.qml"     }   } } It looks like the dynamic library is not loaded when qmlViewer.setMainQmlFile() is called, although the import works as the later creation of TestItem works. From what I’ve read in the docs, the Q_INIT_RESOURCE_EXTERN() macro should be used when dynamic libraries are used which contain resource files. However, it has no effect. Similar threads like this one [qt-project.org] also did not solve the problem. Any ideas how to properly initialize the plugin?

Viewing all articles
Browse latest Browse all 18427

Latest Images

Trending Articles



Latest Images