1
votes

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 happensiamanyone

1 Answers

3
votes

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.