android - 如何使用 Qt 将文件写入 Android 设备?

标签 android qt file

我在 Qt 中创建文件并将其写入 Android 设备时遇到问题。我尝试了几个不同的例子,但没有成功。

此示例应写入内部存储的 Download 文件夹:

QString path = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation);

qDebug() << path; // '/storage/emulated/0/Download'
qDebug() << "Exists? " << QFile::exists(path + "/401891.png"); // This is an existing image in the folder, returns true

QFile testFile(path.append("/Testing.txt"));
testFile.open(QFile::WriteOnly);

QTextStream out(&testFile);
out << "Hello";

testFile.close();
qDebug() << "Exists? " << QFile::exists(path + "/Testing.txt"); // Returns false

我收到此警告:

Warning: QIODevice::write (QFile, "/storage/emulated/0/Download/Testing.txt"): device not open

我缺少什么以及如何解决它?

最佳答案

尽管 list 中声明了权限,但似乎并未应用这些权限。

转到设置 -> 应用程序 -> 应用程序管理器

找到您的应用程序并确保“存储”权限切换为“打开”。

关于android - 如何使用 Qt 将文件写入 Android 设备?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52337354/

相关文章:

c++ - 将 TableView 中的 CheckBox 选中状态绑定(bind)到自定义模型属性

c++ - 如何在使用单个测试项目时将所有 QtTestLib 单元测试的结果组合到一个文件中?

android - RxJava2, Android -> 这个单元测试有什么问题

android - 如何获取 MMS id Android 应用程序

qt - ./ts_calibrate 错误 : ts_open: No such file or directory

python - 变量名似乎被覆盖

java - 在java中测试文件下载

java - url 连接的 url 编码问题

c# - Unity通用关闭按钮C#

file - 编译程序,仅在编译失败时报告(不显示错误)