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)

1
  • When I try: QDir home = QDir::home(); QFile file(home.absoluteFilePath("testAppFile.txt")); The same thing happens
    – iamanyone
    Mar 20, 2013 at 11:05

1 Answer 1

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.

1
  • That's what I am looking for.
    – Amit Yadav
    Dec 27, 2017 at 13:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.