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. Loading a qmldir from a qrc file
Forum Updated to NodeBB v4.3 + New Features

Loading a qmldir from a qrc file

Scheduled Pinned Locked Moved QML and Qt Quick
9 Posts 5 Posters 12.9k 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.
  • B Offline
    B Offline
    bunjee
    wrote on last edited by
    #1

    Greetings,

    I'm trying to load a QML module from the qrc file.

    Here is how my qrc file looks:
    @<RCC>
    <qresource prefix="/">
    <file>content/Main.qml</file>
    <file>content/SkyComponents/PushButton.qml</file>
    <file>content/SkyComponents/qmldir</file>
    </qresource>
    </RCC>@
    Here is how my Main.qml looks:
    @import SkyComponents 1.0

    ...@
    I also added this in my cpp files:
    @wControllerDeclarative->engine()->addImportPath("qrc:/");@

    I get the following error:

    Couldn't create Main QML Object: qrc:/content/Main.qml:3 module "SkyComponents" is not installed

    Is it possible to load qmldir(s) from the qrc file ?

    Thanks.

    B.A.

    1 Reply Last reply
    0
    • T Offline
      T Offline
      thisisbhaskar
      wrote on last edited by
      #2

      can you try
      @
      import content.SkyComponents 1.0
      @
      Not sure if it works, but you can give it a try.

      1 Reply Last reply
      0
      • B Offline
        B Offline
        bunjee
        wrote on last edited by
        #3

        Hi there,

        I tried it with no luck.

        Indeed I want to keep the very same QML files when I'm using qrc or the filesystem.

        Modifying the qml files for any scenario is kind of my last option.

        1 Reply Last reply
        0
        • L Offline
          L Offline
          lgeyer
          wrote on last edited by
          #4

          What does "import tracing":http://www.developer.nokia.com/Community/Wiki/How_to_enable_QML_Import_Traces#QML_IMPORT_TRACE_with_Qt say?

          1 Reply Last reply
          0
          • B Offline
            B Offline
            bunjee
            wrote on last edited by
            #5

            Good call. I did not know this command...

            @QDeclarativeImportDatabase::addImportPath: "qrc:/"
            QDeclarativeImports(qrc:/content/Main.qml)::addImport: "." -1.-1 File as ""
            QDeclarativeImports(qrc:/content/Main.qml)::addImport: "QtQuick" 1.0 Library as ""
            QDeclarativeImports(qrc:/content/Main.qml)::addImport: "Sky" 1.0 Library as ""
            QDeclarativeImports(qrc:/content/Main.qml)::addImport: "SkyComponents" 1.0 Library as ""
            QDeclarativeComponent: Component is not ready
            Couldn't create Main QML Object: qrc:/content/Main.qml:3 module "SkyComponents" is not installed@

            1 Reply Last reply
            0
            • B Offline
              B Offline
              bunjee
              wrote on last edited by
              #6

              Looks like it could be a Qt bug.

              Shall I do a bug report ?

              1 Reply Last reply
              0
              • T Offline
                T Offline
                tipul07
                wrote on last edited by
                #7

                Thanks to vallidor from www.qtcentre.org we have a working model for this:

                http://www.qtcentre.org/threads/43236-Loading-a-qmldir-from-a-qrc-file?p=198993#post198993

                I didn't test it, but sample provided is part of a working solution.

                1 Reply Last reply
                0
                • J Offline
                  J Offline
                  jackyang
                  wrote on last edited by
                  #8

                  My solution is like this :
                  <1>
                  @
                  <RCC>
                  <qresource prefix="/">
                  <file alias="MyComp.qml">myComponentPath/MyComp.qml</file>
                  </qresource>
                  </RCC>
                  @

                  And in my main.qml

                  @
                  import "qrc:/."

                  MyComp {
                  ......
                  }
                  @

                  <2>
                  And I also try to put the path only on qrc's file tag's value :

                  @
                  <RCC>
                  <qresource prefix="/">
                  <file alias="MyCom">myComponentPathFolder</file>
                  </qresource>
                  </RCC>
                  @

                  In my main.qml
                  @
                  import "qrc:/MyCom"
                  MyComp {
                  ......
                  }
                  @

                  It also works!! But there is a bug by this method, thing like when I put many components in that path, it will appear wrong component's declarative as if I put many components on main.qml.

                  No matter what, the first tricks can help you ~

                  1 Reply Last reply
                  0
                  • B Offline
                    B Offline
                    bunjee
                    wrote on last edited by
                    #9

                    Can't seem to load a module on Qt 4.8.3 for now.

                    So:

                    1. I flattened my module directory.

                    2. Copy / pasted all the qml files in the same folder.

                    3. Exported that folder into a qrc file.

                    It works just fine.

                    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