Results 1 to 8 of 8

Thread: Loading a qmldir from a qrc file

  1. #1
    Join Date
    Jan 2007
    Location
    Paris
    Posts
    459
    Thanks
    98
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5

    Default Loading a qmldir from a qrc file

    Greetings Qt centers,

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

    Here is how my qrc file looks:

    Qt Code:
    1. <RCC>
    2. <qresource prefix="/">
    3. <file>content/Main.qml</file>
    4. <file>content/SkyComponents/PushButton.qml</file>
    5. <file>content/SkyComponents/qmldir</file>
    6. </qresource>
    7. </RCC>
    To copy to clipboard, switch view to plain text mode 
    Here is how my Main.qml looks:

    Qt Code:
    1. import SkyComponents 1.0
    2.  
    3. ...
    To copy to clipboard, switch view to plain text mode 
    I also added this in my cpp files:

    Qt Code:
    1. wControllerDeclarative->engine()->addImportPath("qrc:/");
    To copy to clipboard, switch view to plain text mode 
    I get the following error:

    Qt Code:
    1. Couldn’t create Main QML Object: qrc:/content/Main.qml:3 module “SkyComponents” is not installed
    To copy to clipboard, switch view to plain text mode 
    Is it possible to load qmldir(s) from the qrc file ?

    Thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Loading a qmldir from a qrc file

    Couldn’t create Main QML Object: qrc:/content/Main.qml:3 module “SkyComponents” is not installed
    How did you load SkyComponents in your QML?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Jan 2007
    Location
    Paris
    Posts
    459
    Thanks
    98
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5

    Default Re: Loading a qmldir from a qrc file

    Like this in my Main.qml:

    Qt Code:
    1. import SkyComponents 1.0
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Loading a qmldir from a qrc file

    Well that is the problem - you have to access SkyElements in the qrc file... not sure if and how this can be done when using it for import declarations...
    My guess is that you have to "load" all the QML files just like to did for Main.qml, and probably in the order of dependency...
    But that is just a guess.
    Maybe someone with more QML experience can comment on this...
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. #5
    Join Date
    Nov 2010
    Posts
    315
    Thanked 53 Times in 51 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Loading a qmldir from a qrc file

    Quote Originally Posted by bunjee View Post
    I also added this in my cpp files:

    Qt Code:
    1. wControllerDeclarative->engine()->addImportPath("qrc:/");
    To copy to clipboard, switch view to plain text mode 
    Why "qrc:/"? it should be ":/"!

  6. #6
    Join Date
    Jan 2007
    Location
    Paris
    Posts
    459
    Thanks
    98
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5

    Default Re: Loading a qmldir from a qrc file

    I tried both "qrc:/" and ":/" with no success.

    Looks like a qmldir module cannot be loaded from the resource file.

    Nobody knows on Qt Dev net either : http://developer.qt.nokia.com/forums/viewthread/7881/

    It seems to be a tricky subject :-).

  7. #7
    Join Date
    Aug 2011
    Location
    Canada
    Posts
    8
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Loading a qmldir from a qrc file

    did you try:

    Qt Code:
    1. import "qrc:/content/";
    2. import SkyComponents 1.0;
    To copy to clipboard, switch view to plain text mode 

    i tested this on my side, it appears to work as expected:

    Qt Code:
    1. import QtQuick 1.0;
    2. import 'qrc:/builtin/qml/';
    3. import 'qrc:/builtin/js/netsh.js' as Netsh;
    4.  
    5. FrameDark {
    6. id: btnLoginText
    7. width: 150
    8. height: 32
    9. text: "Connect"
    10. anchors.bottom: parent.bottom
    11. anchors.bottomMargin: 0
    12. anchors.horizontalCenter: parent.horizontalCenter
    13. onClicked: { Netsh.loginClicked(); }
    14. }
    To copy to clipboard, switch view to plain text mode 

    actually, i should probably also provide this:

    my qrc:
    Qt Code:
    1. <RCC>
    2. <qresource prefix="/builtin">
    3. <file alias="js/netsh.js">../js/netsh.js</file>
    4. <file alias="qml/qmldir">../qml/qmldir</file>
    5. <file alias="qml/FrameDark.qml">../qml/FrameDark.qml</file>
    6. <file alias="images/FrameDark/FrameDark.png">../images/FrameDark/FrameDark.png</file>
    7. <file alias="images/FrameDark/FrameDarkA.png">../images/FrameDark/FrameDarkA.png</file>
    8. </qresource>
    9. </RCC>
    To copy to clipboard, switch view to plain text mode 

    and the qmldir (brace yourself, it's VERY LONG):
    Qt Code:
    1. FrameDark FrameDark.qml
    To copy to clipboard, switch view to plain text mode 

    and that QML import tracing envvar doodad shows:

    Qt Code:
    1. QDeclarativeImports(file::/builtin/qml/rrcbs/login.qml)::addImport: "." -1.-1 File as ""
    2. QDeclarativeImports(file::/builtin/qml/rrcbs/login.qml)::addImport: "QtQuick" 1.0 Library as ""
    3. QDeclarativeImports(file::/builtin/qml/rrcbs/login.qml)::addImport: "qrc:/builtin/qml/" -1.-1 File as ""
    4. QDeclarativeImports(file::/builtin/qml/rrcbs/login.qml::importExtension: loaded ":/builtin/qml//qmldir"
    5. QDeclarativeImports(file::/builtin/qml/rrcbs/login.qml)::resolveType: "Rectangle" => "QDeclarativeRectangle"
    6. QDeclarativeImports(file::/builtin/qml/rrcbs/login.qml)::resolveType: "Text" => "QDeclarativeText"
    7. QDeclarativeImports(file::/builtin/qml/rrcbs/login.qml)::resolveType: "TextInput" => "QDeclarativeTextInput"
    8. QDeclarativeImports(file::/builtin/qml/rrcbs/login.qml)::resolveType: "FrameDark" => QUrl("qrc:/builtin/qml/FrameDark.qml")
    9. QDeclarativeImports(qrc:/builtin/qml/FrameDark.qml)::addImport: "." -1.-1 File as ""
    10. QDeclarativeImports(qrc:/builtin/qml/FrameDark.qml::importExtension: loaded ":/builtin/qml/qmldir"
    To copy to clipboard, switch view to plain text mode 
    Last edited by vallidor; 3rd August 2011 at 06:26.

  8. The following user says thank you to vallidor for this useful post:

    tipul07 (3rd August 2011)

  9. #8
    Join Date
    Apr 2013
    Posts
    2
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Loading a qmldir from a qrc file

    If someone else have troubles with modules path, and find this thread from search:

    a) Replace qrc imprort to absolute path, to understand what directory you need.
    b) If you have module with a few subfolders, check folder names! It should be just the same as in qmldir, case sensitive.

Similar Threads

  1. Loading a TabLib .a File into project
    By Atais in forum Newbie
    Replies: 6
    Last Post: 9th February 2011, 22:22
  2. QML file not loading external JS file?
    By anothertest in forum Qt Programming
    Replies: 2
    Last Post: 14th April 2010, 09:11
  3. QPixmap not loading image(from file) after deployment.
    By csmithmaui in forum Installation and Deployment
    Replies: 4
    Last Post: 23rd February 2010, 02:44
  4. External Javascript file not loading initially
    By bkudrle in forum Qt Programming
    Replies: 0
    Last Post: 13th March 2009, 17:05
  5. OpenGL file loading formats
    By TheKedge in forum Qt Programming
    Replies: 0
    Last Post: 6th August 2008, 15:44

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.