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. QML loaded from plugin cannot reference local types
Forum Updated to NodeBB v4.3 + New Features

QML loaded from plugin cannot reference local types

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 2 Posters 1.1k 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.
  • G Offline
    G Offline
    gs_chris
    wrote on last edited by
    #1

    Hello,

    we have code that is located in a C++ plugin (actually, a QML resource which is registered as a type via Plugin::registerTypes) which dynamically loads other QML, using a QtQuick.Loader. Lets call the registered type DynaLoader. The application which uses DynaLoader will pass in a string like "Bla.qml".

    Now it turns out that components which themselves reference other locally defined QML types (i.e., types defined in QML files that are located alongside the initially loaded one) cannot be loaded, because the referenced type is not visible. For example, let Bla.qml be:

    @Rectangle {
    AnotherBla {
    }
    }@

    where AnotherBla.qml is located right alongside Bla.qml. Now, when at runtime we say

    @DynaLoader.show = "Bla.qml"@

    we get a message "AnotherBla is not a type".

    I have to mention that all QML files (both in the plugin and in the application) are stored as resources.

    thanks
    Chris

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      Just a quick check. Hope it AnotherBla.qml.. 'A' in file name is capital letter. Are you able to load the AnotherBla.qml directly ? i.e not through Bla.qml.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      0
      • G Offline
        G Offline
        gs_chris
        wrote on last edited by
        #3

        sure I can load it. QtCreator sees it, too. It is only when Bla is loaded dynamically (through code residing in a plugin, as I said) that suddenly AnotherBla cannot be resolved.

        1 Reply Last reply
        0
        • G Offline
          G Offline
          gs_chris
          wrote on last edited by
          #4

          ok, I've found something like a solution. The QML references I pass to the Loader must be relative to the root of the project. If that is the case, everything works. So simply saying
          @DynaLoader.show = "/Bla.qml"@

          causes Bla.qml and all nested components to be resolved correctly

          1 Reply Last reply
          0

          • Login

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