【问题标题】:How to open a file in android with qt having the content URI如何使用具有内容URI的qt在android中打开文件
【发布时间】:2020-03-02 01:48:18
【问题描述】:

如何使用带有 android -content://com.android.providers.downloads.documents/document/raw.pdf 链接的 QFile 打开文件

我尝试了下面的代码,但它显示文件未打开

 QString path("content://com.android.providers.downloads.documents/document/raw.pdf");
 QUrl path_url(path);
 path = path_url.toLocalFile();
 QFile* file = new QFile(path);
 file->open(QIODevice::ReadOnly)

【问题讨论】:

  • 您应该尝试打开输入流来读取文件。像 InputStream 一样 = getContentResolver().openInputStream(path);
  • 这是通过Qt吗?
  • 嘿,@HusniAbdulNazer 你解决问题了吗?我现在也在面对!

标签: android qt qfiledialog qfile qtandroidextras


【解决方案1】:

QQmlFile 可以将其格式化为 /storage/emulated/0/....

QString path("content://com.android.providers.downloads.documents/document/raw.pdf"); QUrl url(路径);

QFile file(QQmlFile::urlToLocalFileOrQrc(url));
  if (!file.open(QFile::ReadOnly)) {
    emit error(tr("Could not open file. '%1'").arg(file.errorString()));
    return;
  } 

example详细实现。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-23
    • 1970-01-01
    • 1970-01-01
    • 2020-10-28
    • 2023-03-09
    相关资源
    最近更新 更多