Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Load shared library with QML files in resource file
Forum Updated to NodeBB v4.3 + New Features

Load shared library with QML files in resource file

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 1 Posters 4.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    feldifux
    wrote on 21 May 2013, 18:56 last edited by
    #1

    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":http://qt-project.org/forums/viewthread/25461 also did not solve the problem.

    Any ideas how to properly initialize the plugin?

    Founder of Felgo SDK - http://felgo.com/qt

    Felgo simplifies

    • Mobile App Dev with Qt esp. iOS & Android
    • Game Development with Qt

    What others say

    Felgo scored #1 in Cross-Platform App Development Tools Report - see why: https://goo.gl/rgp3rq

    1 Reply Last reply
    0
    • F Offline
      F Offline
      feldifux
      wrote on 22 May 2013, 08:34 last edited by
      #2

      I found out, that putting a DynamicallyLoadedTestItem into the main.qml file did work! But only if the import of the plugin is added in the main.qml, otherwise the same error with type not being found occurs.

      Here is the source code:
      @
      // main.qml:

      import QtQuick 1.1
      import MyPlugin 1.0

      Item {
      // this DOES WORK! but only if import MyPlugin 1.0 is added in main.qml
      DynamicallyLoadedTestItem {}

      // this causes the error "TestItem is not a Type"
      TestItem {}
      }

      // DynamicallyLoadedTestItem.qml:

      import MyPlugin 1.0

      TestItem { }
      @

      It seems that in the first loaded qml file the dynamic library is not loaded, but when another file is loaded it is available. Shouldn't the QML engine take care of completely loading the library before initializing it? Or how can I load it in advance so the library is accessible when the first qml file gets parsed?

      Founder of Felgo SDK - http://felgo.com/qt

      Felgo simplifies

      • Mobile App Dev with Qt esp. iOS & Android
      • Game Development with Qt

      What others say

      Felgo scored #1 in Cross-Platform App Development Tools Report - see why: https://goo.gl/rgp3rq

      1 Reply Last reply
      0

      2/2

      22 May 2013, 08:34

      • Login

      • Login or register to search.
      2 out of 2
      • First post
        2/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved