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. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Cascades Development

Reply
Contributor
sensationality
Posts: 21
Registered: ‎02-22-2013
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

Please use plain text.
Developer
Zmey
Posts: 919
Registered: ‎12-18-2012

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"

 

 

Please use plain text.
Developer
simon_hain
Posts: 13,830
Registered: ‎07-29-2008
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
Please use plain text.