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
New Contributor
TheRain
Posts: 9
Registered: ‎09-26-2012
My Device: Dev Alpha
Accepted Solution

Beta 3: Reference image from sandbox data folder

Hey all,

 

Prior to the beta 3 native SDK, I was able to reference an image downloaded to the data folder by setting:

 

imageSource: "../../../data/image.jpg"

 

-  This is no longer working for me- or there may be something else wrong, but I'm not seeing anything in my console output about it.   

 

If the above won't work in beta 3 anymore, anyone know what would?

 

 

Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10

Re: Beta 3: Reference image from sandbox data folder

Try removing one of the levels of ".." in that.

 

To see the log output now, it looks like you may need to log in with SSH and use the "slog2info" command.  What's working for me right now is to run "slog2info -w" as that way I can leave it running and it picks up the output from each new app.

 

There was a session at the Jam today which covered this (JAM10) a bit, so once the sessions are put up you may be able to learn more details from that.


Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
New Contributor
TheRain
Posts: 9
Registered: ‎09-26-2012
My Device: Dev Alpha

Re: Beta 3: Reference image from sandbox data folder

Thanks, one level doesn't seem to be fixing it though- I'll have to try out the logging details you mentioned and see if I can glean any useful information from it.

 

I'm at the jam conference too- it's been awesome so far!  I wasn't in the session where this topic was discussed apparently.

New Contributor
TheRain
Posts: 9
Registered: ‎09-26-2012
My Device: Dev Alpha

Re: Beta 3: Reference image from sandbox data folder

BUMP on this.  Hi guys,  I haven't been able to glean any good information about this from logging aside from that ".../.../.../data/myimage.jpg" no longer works in QML.  Does anyone know how I can reference an image in the data folder now with beta 3?   Or if that's not possible is there any way to download an image from the web, and then reference it from QML?  

 

I have tried referencing the data folder:

".../.../.../data/myimage.jpg"

".../.../data/myimage.jpg"

".../data/myimage.jpg"

"data/myimage.jpg"

"asset:///.../.../.../data/myimage.jpg"

"file:///data/myimage.jpg"

"file:///myimage.jpg"

"data:///myimage.jpg"

Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10

Re: Beta 3: Reference image from sandbox data folder

I'm pretty sure that somewhere in https://developer.blackberry.com/cascades/documentation/dev/upgrading/index.html or the linked child pages, you'll find your answer.

 

It appears if you aren't using "asset:" then the paths should finally be rooted in the current directory, which should be the app's folder under /accounts/1000/appdata.  Depending on where these images are, you could then get to them using something like "app/native/data/image.jpg" or "data/image.jpg".  It seems you've probably already tried those, however, but maybe after reading that page and Data and filesystem changes and Application changes you'll figure it out.

 

I haven't explored this all yet. It may be that some of those changes are specific to ImageView, others to QMLDocument, and others to different things. I'll let you know if I figure it out.


Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
New Contributor
TheRain
Posts: 9
Registered: ‎09-26-2012
My Device: Dev Alpha

Re: Beta 3: Reference image from sandbox data folder

Thanks Peter- your mention of absolute path shook something loose and I remember someone in one of the bb jam sessions mentioning something about a temporary limitation in current iteration of the OS about having to use an absolute path.   I gave that a try and it is working.   So I guess that may be the solution for now.

 

I am generating a listview data model in code and creating paths through string manipulation to the files after they are downloaded.   I think it should be possible, for now, to use that to dynamically get the absolute path of the files as well, and pass them in to QML from C++ code.

New Contributor
TheRain
Posts: 9
Registered: ‎09-26-2012
My Device: Dev Alpha

Re: Beta 3: Reference image from sandbox data folder

Peter, thank you again for your help on this.   I looked all through the documentation and I haven't found the information needed to sort this out.   But with your help I have it working.   For anyone else that this might be helpful to, here's a little more detail on the solution (for beta 3 at least) -  

 

In native C++ code, using the relative path of "data/myimage.jpg" works if I am downloading a file and saving to my app's sandboxed data folder.   However, the same can't be used when referencing the file in QML.  At the moment it looks like only the absolute path of the saved file can be used in QML.   Here is how I obtain that absolute path dynamically in C++ code using QT frameworks:

 

QFile file("data/myimage.jpg");

QFileInfo fileInfo(file);

QString qmlPath(fileInfo.absoluteFilePath());

 

The resulting QString qmlPath can be passed to QML in a few ways I believe.  Personally I am populating a ListView as a grid of images and so I am creating a QVariantList of QVariantMaps and using GroupDataModel passed to Listview. 

Developer
pepe_ugalde
Posts: 64
Registered: ‎09-10-2012
My Device: Developer

Re: Beta 3: Reference image from sandbox data folder

So is there no way of getting images in QML from the data/ folder not involving C++?

Or at least any way of logging all available directories from a function in a QML file?