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
Highlighted
Developer
Posts: 17,012
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Path to database from qml?

I want to use a listview to show entries from a sql database located in the data folder.

How can i reference it in qml?

 

source: "../../../data/logs.db"

 gets me

 SqlDataAccess error:  "unable to open new database file "/apps/com.isec7.bb10.testDev_c7_bb10_sapfb6e0ff_/data/logs.db""

The db is in the data directory, so the path looks correct.

 it works when i read the path from c++, but i would like to know why it is not working from qml directly.

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 1,524
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: Path to database from qml?

Could you try:

 

source: "file://../../../data/logs.db"

If this won't work then I assume it requires an absolute path together with file:// prefix.

 

This page suggests using QDir from C++ code to retrieve the working directory and passing it back to QML (at the bottom of page):

 

http://developer.blackberry.com/cascades/documentation/device_platform/filesystem/

 


Andrey Fidrya, @zmeyc on twitter
Developer
Posts: 17,012
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Path to database from qml?

also does not work:
"unable to open new database file "/data/logs.db"

it works with a property from c++ where i return
QDir::homePath() + QDir::separator() + "logs.db";
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Path to database from qml?

Can you also try an absolute path?

Their QML implementation has been rather self-conflicted in the past about asset: vs. file: and relative vs. absolute paths. The latest versions supposedly treat all relative paths as relative to, or maybe it's to the location of the QML file, or maybe it's the root QML file. I honestly haven't been able to pin it down with 100% consistency across the various uses (e.g. ImageView source, includes, etc). In your case, absolute path may work, either with or without file:// (or file:///) in front...

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!