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)

4

1 回答 1

3

好的,我自己偶然发现了答案:

QFile file(QDir::currentPath() + "/shared/documents/yourfile.txt");

if (file.open(QIODevice::WriteOnly)) {
    QTextStream stream(&file);
    stream << "DATA HERE \n";
}

原来每个应用程序都可以访问自己的工作目录。所以正在创建文件,我只是在设备上看不到它:

制作路径:“/shared/documents/”将文件放在我可以在文件管理器中看到的地方

(希望这对以后遇到类似问题的人有所帮助)

这是一个有用的链接,它解释了目录和当前路径。

于 2013-03-20T11:28:02.360 回答