Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Selecting a file on Android via content provider

Selecting a file on Android via content provider

Scheduled Pinned Locked Moved Solved Mobile and Embedded
2 Posts 1 Posters 76 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    swurl
    wrote on 20 Mar 2025, 17:58 last edited by
    #1

    When I select a file via QML's FileDialog and pass it along to C++, I'm able to get the base directory (sort of) and filename:

    void example(const QString &folder, const QString &file) {
        QString filename = QFileInfo(file).fileName();
        QString folderName = folder;
    
        QDir fileDir = folder;
    
        QString name = fileDir.filePath(filename);
    
        name.replace("file://", "");
    
        qDebug() << "Filename:" << filename;
        qDebug() << "Dir name:" << folderName;
        qDebug() << "Dir:" << fileDir;
        qDebug() << "Final name:" << name;
    }
    

    This outputs the following:

    Filename: "20250305_215011.jpg"
    Dir name: "file:///storage/emulated/0/Android/data/com.example.example/files/Download"
    Dir: QDir( "file:///storage/emulated/0/Android/data/com.example.example/files/Download" , nameFilters = { "*" },  QDir::SortFlags( Name | IgnoreCase ) , QDir::Filters( Dirs|Files|Drives|AllEntries ) )
    Final name: "/storage/emulated/0/Android/data/com.example.example/files/Download/20250305_215011.jpg"
    

    Filename is correct, however, the file itself is in /storage/emulated/0/Download, not whatever that internal storage thing is. I can confirm this by seeing that /storage/emulated/0/Android/data/com.example.example/files/Download is empty.

    How can I get the correct directory to show up here? If I can only get the app's internal download folder, how can I ensure that the file is actually copied to the internal download folder?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      swurl
      wrote on 20 Mar 2025, 18:15 last edited by
      #2

      Nevermind, turns out QFile can read the content:// URI directly.

      1 Reply Last reply
      0
      • S swurl has marked this topic as solved on 20 Mar 2025, 18:15

      1/2

      20 Mar 2025, 17:58

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved