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


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
New Developer
Posts: 26
Registered: ‎02-22-2013
My Device: BlackBerry Z10
My Carrier: Telus

Using QFile to write to file

Hey guys I've gotten a lot of help for the first two questions I asked here so I thought I'd ask again. 

 

I'm implementing a leaderboard / highscore board in my game, for which I want to read from a file the current high scores, and write to it if there is a new high score. 

I read this: http://developer.blackberry.com/native/documentation/bb10/com.qnx.doc.native_sdk.devguide/com.qnx.do... and saw you can only write in /data.

 

I'm not sure how to implement this. What do I put in here:

QFile file("data/documents/testfile.txt");
... then use out << scores;

 

That doesn't seem to work. I can read high scores fine from assets folder, but not sure how to write them back for later.

 

Thanks

Highlighted
Developer
Posts: 1,524
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: Using QFile to write to file

Hi,

 

The directory should be created first:

QDir dir;

dir.mkpath("data/documents");
 
The file should be opened before writing:
QFile file("data/documents/testfile.txt");
file.open(QIODevice::WriteOnly | QIODevice::Text); // remove QIODevice::Text if the file is binary

 

Please check this page for details:

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

 

When absolute URL is needed the following line can be used:

QDir::homePath() + "/data/filename"

 

 


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

Re: Using QFile to write to file

as a sidenote, you can also write in the tmp folder or the shared folder.
----------------------------------------------------------
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