Details
-
Bug
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
6.5.3
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.