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

QUrl on Android should consider 'content' as local files.

    XMLWordPrintable

Details

    • Android

    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

        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:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes