PDA

View Full Version : Loading a qmldir from a qrc file



bunjee
19th July 2011, 11:28
Greetings Qt centers,

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.

high_flyer
20th July 2011, 10:12
Couldn’t create Main QML Object: qrc:/content/Main.qml:3 module “SkyComponents” is not installed
How did you load SkyComponents in your QML?

bunjee
22nd July 2011, 14:58
Like this in my Main.qml:


import SkyComponents 1.0

high_flyer
22nd July 2011, 15:06
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...

MarekR22
25th July 2011, 14:36
I also added this in my cpp files:


wControllerDeclarative->engine()->addImportPath("qrc:/");
Why "qrc:/"? it should be ":/"!

bunjee
27th July 2011, 23:52
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 :-).

vallidor
3rd August 2011, 06:43
did you try:


import "qrc:/content/";
import SkyComponents 1.0;


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


import QtQuick 1.0;
import 'qrc:/builtin/qml/';
import 'qrc:/builtin/js/netsh.js' as Netsh;

FrameDark {
id: btnLoginText
width: 150
height: 32
text: "Connect"
anchors.bottom: parent.bottom
anchors.bottomMargin: 0
anchors.horizontalCenter: parent.horizontalCenter
onClicked: { Netsh.loginClicked(); }
}


actually, i should probably also provide this:

my qrc:

<RCC>
<qresource prefix="/builtin">
<file alias="js/netsh.js">../js/netsh.js</file>
<file alias="qml/qmldir">../qml/qmldir</file>
<file alias="qml/FrameDark.qml">../qml/FrameDark.qml</file>
<file alias="images/FrameDark/FrameDark.png">../images/FrameDark/FrameDark.png</file>
<file alias="images/FrameDark/FrameDarkA.png">../images/FrameDark/FrameDarkA.png</file>
</qresource>
</RCC>

and the qmldir (brace yourself, it's VERY LONG):

FrameDark FrameDark.qml

and that QML import tracing envvar doodad shows:


QDeclarativeImports(file::/builtin/qml/rrcbs/login.qml)::addImport: "." -1.-1 File as ""
QDeclarativeImports(file::/builtin/qml/rrcbs/login.qml)::addImport: "QtQuick" 1.0 Library as ""
QDeclarativeImports(file::/builtin/qml/rrcbs/login.qml)::addImport: "qrc:/builtin/qml/" -1.-1 File as ""
QDeclarativeImports(file::/builtin/qml/rrcbs/login.qml::importExtension: loaded ":/builtin/qml//qmldir"
QDeclarativeImports(file::/builtin/qml/rrcbs/login.qml)::resolveType: "Rectangle" => "QDeclarativeRectangle"
QDeclarativeImports(file::/builtin/qml/rrcbs/login.qml)::resolveType: "Text" => "QDeclarativeText"
QDeclarativeImports(file::/builtin/qml/rrcbs/login.qml)::resolveType: "TextInput" => "QDeclarativeTextInput"
QDeclarativeImports(file::/builtin/qml/rrcbs/login.qml)::resolveType: "FrameDark" => QUrl("qrc:/builtin/qml/FrameDark.qml")
QDeclarativeImports(qrc:/builtin/qml/FrameDark.qml)::addImport: "." -1.-1 File as ""
QDeclarativeImports(qrc:/builtin/qml/FrameDark.qml::importExtension: loaded ":/builtin/qml/qmldir"

Zifix
17th January 2017, 22:09
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.