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. Using local types in remote qml files
QtWS25 Last Chance

Using local types in remote qml files

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 2 Posters 1.3k Views
  • 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.
  • D Offline
    D Offline
    DerMas
    wrote on last edited by
    #1

    I am currently trying to import qml files from a remote directory (see "Thread":http://qt-project.org/forums/viewreply/172115).
    So far, I can load qml files that are in the remote dir, but when I try to use qmls (types) from my local directory, the access doesnt work "Type LocalType unavailable". How can I fix this? The access works if I use "Qt.createQmlObject", so I hope it will work for those imports too.

    For better comprehension here is an example filetree:

    local (/home/user/workspace/qml)

    • main.qml (imports page1.qml with remote import)
    • button.qml

    remote (192.168.1.23/qml)

    • page1.qml (uses button.qml)
    1 Reply Last reply
    0
    • C Offline
      C Offline
      chrisadams
      wrote on last edited by
      #2

      The types which are used in the QML file which comes from a remote directory import MUST be exposed into a type namespace which is imported by that remote file. You cannot use just the Button type without importing anything in page1.qml, as the component base url of page1.qml is different to the component base url of main.qml.

      In short, if you want to do this, button.qml should be put into a module which is imported by both main.qml and page1.qml.

      Cheers,
      Chris.

      1 Reply Last reply
      0
      • D Offline
        D Offline
        DerMas
        wrote on last edited by
        #3

        Thanks for the answer. So I will use your suggestion with the seperate module.

        But I guess I didnt completly understand the first part of your answer, could you give a quick code example, if my example doesnt fit to what you meant?

        main.qml:

        @import QtQuick 2.2
        import “http://192.168.178.33/content” as Remote // => is this the type namespace you talked about?

        Rectangle {
        Remote.Page1 {}
        }@

        1 Reply Last reply
        0
        • C Offline
          C Offline
          chrisadams
          wrote on last edited by
          #4

          Well, that will import the types defined in the remote directory listing qmldir file into the Remote namespace.

          But what I meant was that the local types used within a file from the remote should be within an explicit type namespace.

          EG, let us assume that locally you have:

          main.qml
          MyButton.qml

          and remotely you have:

          qmldir
          Page.qml

          and for the sake of argument, if Page.qml has a declaration of an instance of MyButton in it, then this will not work unless MyButton comes from an explicitly defined type namespace (ie, not the implicit cwd import).

          So, to make this work, you'd need to install a new, module-specification qmldir file plus the MyButton.qml file to your local QML2 import directory, and import that module within the MyForm.qml file (which comes from the remote).

          eg, if you install the qmldir + MyButton.qml into /usr/lib/qt5/qml/com/your/company/components/ then you could do:

          @
          // main.qml
          import QtQuick 2.2
          import com.your.company.components 1.0
          import “http://192.168.178.33/content” as Remote

          Item {
          Remote.Page {
          // ...
          }

          MyButton {
              // ...
          }
          

          }
          @

          where the (remote) Page.qml has:

          @
          // main.qml
          import QtQuick 2.2
          import com.your.company.components 1.0

          Item {
          MyButton {
          // this should work because when it's compiled
          // the MyButton type is available from the (local) module.
          }
          }
          @

          Cheers,
          Chris.

          1 Reply Last reply
          0
          • D Offline
            D Offline
            DerMas
            wrote on last edited by
            #5

            Thanks, that great answer cleared everything up :)

            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