I am battling to write some data to a simple text file
Here is my code:
QFile file(app->applicationDirPath() + "/data/testfile.txt");
if (file.open(QIODevice::WriteOnly)) {
QTextStream stream(&file);
stream << "DATA HERE \n";
}
The app compiles and runs fine.
Just I cant find the file, or more likely: it is not being created
Where am I going wrong? :)
Thanks
Extra Info:
Run: on my device (BlackBerry Z10)
IDE: QNX IDE (Native SDK) / (Cascades)
Example code is located in: TestApp::TestApp(bb::cascades::Application *app)
: QObject(app)
Okay, I kinda stumbled upon the answer myself:
QFile file(QDir::currentPath() + "/shared/documents/yourfile.txt");
if (file.open(QIODevice::WriteOnly)) {
QTextStream stream(&file);
stream << "DATA HERE \n";
}
Turns out each application has access to its own working directory. So the file was being created, I just could not see it on the device:
making the path: "/shared/documents/" made the file in a place where I could see it in the file manager
(hope this helps anyone who has a similar problem in the future)
This is a useful link, which explains the directories & current path.