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

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.



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

Re: Using QFile to write to file



The directory should be created first:

QDir dir;

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:



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

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



Andrey Fidrya, @zmeyc on twitter
Posts: 17,012
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