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

QFile wrong file size/truncated teading when using AndroidContentFileEngine

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P2: Important
    • Resolution: Done
    • Affects Version/s: 5.15.0
    • Fix Version/s: 5.15.1
    • Component/s: Core: I/O
    • Labels:
      None
    • Environment:
      tested on Android 8.1.0 on Samsung Galaxy Tab A
    • Platform/s:
      Android

      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.

        Attachments

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

          Activity

            People

            Assignee:
            andysh Andy Shaw
            Reporter:
            ivang Ivan Golubovic
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Gerrit Reviews

                There are no open Gerrit changes