Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Regular Contributor
xhotkey
Posts: 53
Registered: ‎09-19-2012
My Device: 9700

issues about compiling resources to speed up qml loading

[ Edited ]

In order to speed up qml loading, I followed this to compile resources:

https://developer.blackberry.com/cascades/documentation/getting_started/tools/compiling.html

 

Issue:

 can't build, with error:

Could not find qmake configuration directoryCould not find qmake configuration fileUsing OS scope before setting MAKEFILE_GENERATORmake[2]: *** No rule to make target `assets.qrc', needed by `o.le-v7-g/.rcc/qrc_assets.cpp'.  Stop.

 

Solution: The tutorial is misleading, the pro file should be :

 

RESOURCES += qrc-assets.qrc

Question 1:

Is this a way to hide and protect the source code of qml file? If not , how?

I can still see qml source in .bar file.

 Question 2:

I didn't see any effects, do I need to change * to specific file name?

<asset path="assets" dest="assets">
    <exclude name="**/*.qml"/>
</asset>
Developer
mzex
Posts: 368
Registered: ‎06-30-2012
My Device: Playbook, Z10LE, DevAlpha C

Re: issues about compiling resources to speed up qml loading

I also tried to compile resources, but application fail to start. I saw that error in tutorial too, and i corrected that. You dont need to add this line 

<asset path="assets" dest="assets">
    <exclude name="**/*.qml"/>
</asset>

 to bar-desciptor.xml , insteed you need to modify that line, because you already have it. Just modify this line

"<asset path="assets">assets</asset>" to that above, and you will not get resources inside .bar file anymore.

But something else is missing, application cannot start.

Developer
strobejb
Posts: 282
Registered: ‎10-15-2012
My Device: bb10 developer

Re: issues about compiling resources to speed up qml loading

I had the same issue. I fixed it by specifying the "qrc:/" prefix when loading my qml.

 

Change this:

 

QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);

 

to this:


QmlDocument *qml = QmlDocument::create("qrc:/assets/main.qml").parent(this);


See: http://supportforums.blackberry.com/t5/Cascades-Development/Compiled-QML-resources/td-p/2096987

Regular Contributor
xhotkey
Posts: 53
Registered: ‎09-19-2012
My Device: 9700

Re: issues about compiling resources to speed up qml loading

I changed to QmlDocument *qml = QmlDocument::create("qrc:/main.qml").parent(this);

 

 

But:

 

slogger2 buffer handle not initialized. ../../lgmon_api.c, logEvent(), around line 578!
bb::cascades::QmlDocument: error when loading QML from:   QUrl( "qrc:/main.qml" ) 
  --- errors:  (qrc:/main.qml: File not found)
bb::cascades::QmlDocument:createRootObject document is not loaded or has errors, can't create root

Developer
strobejb
Posts: 282
Registered: ‎10-15-2012
My Device: bb10 developer

Re: issues about compiling resources to speed up qml loading

Try including the assets directory in the path:

"qrc:/assets/main.qml"
Regular Contributor
xhotkey
Posts: 53
Registered: ‎09-19-2012
My Device: 9700

Re: issues about compiling resources to speed up qml loading

[ Edited ]
you mean QmlDocument *qml = QmlDocument::create("qrc:/assets/main.qml").parent(this);? it works for this line. But, there's some other error in qml: import "common" bb::cascades::QmlDocument: error when loading QML from: QUrl( "qrc:/assets/main.qml" ) --- errors: (qrc:/assets/main.qml:2:1: "Common": no such directory)
Developer
strobejb
Posts: 282
Registered: ‎10-15-2012
My Device: bb10 developer

Re: issues about compiling resources to speed up qml loading

Theres no magic going on here -

Use QmlDocument::create() as before, but specify the correct path to your qml file. Look at the example I provided above.
Developer
strobejb
Posts: 282
Registered: ‎10-15-2012
My Device: bb10 developer

Re: issues about compiling resources to speed up qml loading

ok I see you updated your question -

Make sure you include all of your QML in your assets.qrc file. I'm using assets-in-subdirectories as well and I can confirm everything is working as you would expect it to. No changes were necessary other than using the qrc:/ prefix
Regular Contributor
xhotkey
Posts: 53
Registered: ‎09-19-2012
My Device: 9700

Re: issues about compiling resources to speed up qml loading

I need to manually add each qml file? That's not so smart I think.

Anyway, my qrc file is :

<!DOCTYPE RCC>
<RCC version="1.0">
<qresource>
<file>assets/main.qml</file>
<file>assets/Common/ToolContainer.qml</file>
<file>assets/Common/ToolItem.qml</file>
<file>assets/Common/ToolPage.qml</file>

...

</qresource>
</RCC>

 

My xml file has:

<asset path="assets" dest="assets">
<exclude name="**/*.qml"/>
</asset>

 

My pro file ends with:

RESOURCES += qrc-assets.qrc
DEPENDPATH += assets

 

And I change 

import bb.cascades 1.0
import "Common"

to

import bb.cascades 1.0
import "qrc:/Common"

 

Still:

 

bb::cascades::QmlDocument: error when loading QML from: QUrl( "qrc:/assets/main.qml" )
--- errors: (qrc:/assets/main.qml:2:1: "qrc:/Common": no such directory)
bb::cascades::QmlDocument:createRootObject document is not loaded or has errors, can't create root

 

BTW, should I change

imageSource: "asset:///images/icon_vibro.png"

to

imageSource: "qrc:/asset/images/icon_vibro.png" ?

Developer
strobejb
Posts: 282
Registered: ‎10-15-2012
My Device: bb10 developer

Re: issues about compiling resources to speed up qml loading

Yes: you need to add every QML into the <qresource> section. But it is trivial to create a python script that auto-generates this file for you.

No: don't change anything else - everything will work as expected from within the qml files themselves, unless you have instances where you are not using the asset:// selector. In those cases, make sure you specify the full filepath with the file:// selector

i.e.
imageSource: "asset:///images/icon_vibro.png" // OK

imageSource: "images/icon_vibro.png" // NOT OK - change to:


imageSource: "file:///accounts/1000/...../images/icon_vibro.png"

.. or whatever the full path to your app is.