Loading a qmldir from a qrc file



  • 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.



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



  • 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.





  • 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@



  • Looks like it could be a Qt bug.

    Shall I do a bug report ?



  • 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.



  • 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 ~



  • 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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.