1

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)

iamanyone
  • 429
  • 2
  • 10
  • When I try: `QDir home = QDir::home(); QFile file(home.absoluteFilePath("testAppFile.txt"));` The same thing happens – iamanyone Mar 20 '13 at 11:05

1 Answers1

3

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.

iamanyone
  • 429
  • 2
  • 10