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. QDir::entryList only shows todays files
Qt 6.11 is out! See what's new in the release blog

QDir::entryList only shows todays files

Scheduled Pinned Locked Moved Solved Mobile and Embedded
6 Posts 2 Posters 2.0k Views 1 Watching
  • 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.
  • M Offline
    M Offline
    Michel de Boer
    wrote on last edited by
    #1

    I have this code to run on on Android:

    QDir dir(path);
    const auto files = dir.entryList({"SPIRAL_*.json"}, QDir::Files, QDir::Time);
    

    When I run this on a phone with Android 9 then I get all "SPIRAL_*.json" files that are present in the directory 'path'.

    When I run this on a phone with Android 13 then I get only all "SPIRAL_*.json" files with modification date of today. When I look on the phone itself I can see that there are more files on older dates.

    Any idea what's going wrong here and how to fix it?

    ekkescornerE 1 Reply Last reply
    0
    • M Michel de Boer

      I have this code to run on on Android:

      QDir dir(path);
      const auto files = dir.entryList({"SPIRAL_*.json"}, QDir::Files, QDir::Time);
      

      When I run this on a phone with Android 9 then I get all "SPIRAL_*.json" files that are present in the directory 'path'.

      When I run this on a phone with Android 13 then I get only all "SPIRAL_*.json" files with modification date of today. When I look on the phone itself I can see that there are more files on older dates.

      Any idea what's going wrong here and how to fix it?

      ekkescornerE Offline
      ekkescornerE Offline
      ekkescorner
      Qt Champions 2016
      wrote on last edited by
      #2

      @Michel-de-Boer perhaps this is caused by Android changing access to file storage.
      Qt just has fixed many things with QFile, QDir, ...
      https://www.qt.io/blog/qt-for-android-storage-updates

      ekke ... Qt Champion 2016 | 2024 ... mobile business apps

      M 1 Reply Last reply
      0
      • ekkescornerE ekkescorner

        @Michel-de-Boer perhaps this is caused by Android changing access to file storage.
        Qt just has fixed many things with QFile, QDir, ...
        https://www.qt.io/blog/qt-for-android-storage-updates

        M Offline
        M Offline
        Michel de Boer
        wrote on last edited by
        #3

        @ekkescorner Thanks for your reply. I think you are right. My observation that it only returned today's files was wrong. It only returns the files that have been created by the particular app instance itself!
        What a mess the made of it.
        The directory is a public directory obtained by

        Environment.getExternalStoragePublicDirectory
        

        As a test I just tried with Java to see what I get with this:

        File[] files = path.listFiles(); // path is a subdir in the external storage public dir
        

        I get the same issue. Only files created by the current app instance itself. I had a mix of files created by a debug version and a released version from the app store.
        Even if I uninstall my official released version from the app store and then re-install from the app store, then with the re-installed version I cannot see the files created by the previous install anymore. And the files I really there when I look in the directory (with adb or a file manager).

        ekkescornerE 1 Reply Last reply
        0
        • M Michel de Boer

          @ekkescorner Thanks for your reply. I think you are right. My observation that it only returned today's files was wrong. It only returns the files that have been created by the particular app instance itself!
          What a mess the made of it.
          The directory is a public directory obtained by

          Environment.getExternalStoragePublicDirectory
          

          As a test I just tried with Java to see what I get with this:

          File[] files = path.listFiles(); // path is a subdir in the external storage public dir
          

          I get the same issue. Only files created by the current app instance itself. I had a mix of files created by a debug version and a released version from the app store.
          Even if I uninstall my official released version from the app store and then re-install from the app store, then with the re-installed version I cannot see the files created by the previous install anymore. And the files I really there when I look in the directory (with adb or a file manager).

          ekkescornerE Offline
          ekkescornerE Offline
          ekkescorner
          Qt Champions 2016
          wrote on last edited by
          #4

          @Michel-de-Boer yep. this decision made by Google makes it much more difficult to deal with files.
          take a look at https://bugreports.qt.io/browse/QTBUG-98974

          ekke ... Qt Champion 2016 | 2024 ... mobile business apps

          M 1 Reply Last reply
          0
          • ekkescornerE ekkescorner

            @Michel-de-Boer yep. this decision made by Google makes it much more difficult to deal with files.
            take a look at https://bugreports.qt.io/browse/QTBUG-98974

            M Offline
            M Offline
            Michel de Boer
            wrote on last edited by
            #5

            @ekkescorner I will go for private app storage with android:hasFragileUserData="true" in the android manifest. My reason for using public storage before is to protect user stored data from being deleted during a re-install of the app.
            Private storage still allows the simplicity of use an ordinary filesystem. SAF is too complicated for my needs with the content and tree URIs. It also makes the user experience cumbersome. Mediastore does not apply to my case as I deal with json files associated with a thumbnail picture (I handle 2 files as a single logical entity).
            IMHO the file handling in Android seems broken. I can write with my app in public space, but after a re-install I cannot read the files I have written before. That does not make sense.
            It must be hard for Qt to deal with this model in a system-independent way.

            ekkescornerE 1 Reply Last reply
            0
            • M Michel de Boer

              @ekkescorner I will go for private app storage with android:hasFragileUserData="true" in the android manifest. My reason for using public storage before is to protect user stored data from being deleted during a re-install of the app.
              Private storage still allows the simplicity of use an ordinary filesystem. SAF is too complicated for my needs with the content and tree URIs. It also makes the user experience cumbersome. Mediastore does not apply to my case as I deal with json files associated with a thumbnail picture (I handle 2 files as a single logical entity).
              IMHO the file handling in Android seems broken. I can write with my app in public space, but after a re-install I cannot read the files I have written before. That does not make sense.
              It must be hard for Qt to deal with this model in a system-independent way.

              ekkescornerE Offline
              ekkescornerE Offline
              ekkescorner
              Qt Champions 2016
              wrote on last edited by
              #6

              @Michel-de-Boer thx for your info.
              never used hasFragileUserData before - it's now on my TODO to take a look at this.
              have two apps where I have to deal with scoped storage - looking forward how well the Qt impl in 5.15.13 is done - testing 5,15,13 this week

              ekke ... Qt Champion 2016 | 2024 ... mobile business apps

              1 Reply Last reply
              0
              • M Michel de Boer has marked this topic as solved on

              • Login

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