Details
Description
There seems to be a bug in Qt's AndroidContentFileEngine and handling of androids ContentProvider/ContentResolver handling
I have file.data 699837 bytes long file stored in Downloads folder.
auto selected_path = QFileDialog::getOpenFileName(); // returne path is: "content://com.android.providers.downloads.documents/document/raw%3A%2Fstorage%2Femulated%2F0%2FDownload%2Ffile.data" QFile f(selected_path); qDebug() << f.size();// returns size as 326 bytes. if (f.open(QIODevice::ReadOnly)) { #if 1 QByteArray data = f.readAll(); qDebug() << data.size() << f.size(); // also prints 326 326 bytes #else // reading data 1 byte at the time until end QByteArray data; while (!f.atEnd()) { char b; if (f.read(&b, 1) == 1) { data.append(b); } } qDebug() << data.size() << f.size(); // prints 16384 326 bytes #endif }
In both cases data read is actual beginning of the file.
Note if I tweak path like:
selected_path.remove(0, 65); selected_path.replace("%3A", ":"); selected_path.replace("%2F", "/"); // path becomes "/storage/emulated/0/Download/file.data"
and use direct path to file, all starts to work normally f.size(), f.readAll() etc. read/report correct sizes.