Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-120913

QUrl always incorrectly returns false on isLocalFile() with 'content' urls on Android

    XMLWordPrintable

Details

    • Android
    • 2024wk20s2FOQtforAndroid

    Description

      I was happy to read the blog: https://www.qt.io/blog/qt-for-android-storage-updates

      which helped a lot in making my code cross-platform.
       

      There is a rather annoying problem left, when the file dialog is used the selected files are all URLs. On Linux they start with file://, and as expected on Android they start with 'content://'.

      The problem is that the code that handles the user-selection would look something like this;

              const QUrl url(addedFiles.at(index));
              assert (url.isLocalFile());
              QString path = url.toLocalFile();
              QFileInfo info(path);
              m_filesize = info.size();

      The point here is that we can only use QFile or QFileInfo on local files, so we assert and then use the proper conversion.

      The problem is that this needs rewriting on Android since:

      • A 'content://' url is not seen as local, while it most of the time is.
      • A QFile / QFileInfo requires the URL instead of the local path on Android.
      • On Android the 'toLocalFile' will return an empty string.

      To make this kind of code actually re-usable and cross platform I suggest that the 'content://' type urls are seen on Android as local and as such the toLocalFile will return the full url on Android so the fileinfo will actually do the right thing.

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              qtandroidteam Qt Android Team
              tomz Tom Zander
              Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes