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

Can't write to external storage anymore under Android

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • Not Evaluated
    • None
    • 5.14.2
    • Extras: Android
    • None
    • Android

    Description

      This simple program:

      
      #include <QApplication>
      #include <QDialog>
      #include <QLabel>
      #include <QDir>
      #include <QStandardPaths>
      #include <QFile>
      #include <QTextStream>
      #include <QVBoxLayout>
      
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
          QDialog dlg;
      
          dlg.setLayout( new QVBoxLayout() );
      
          QString path = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
      
          if ( !QDir(path).exists() )
          {
              if ( QDir().mkdir(path) )
                  dlg.layout()->addWidget( new QLabel( "Could create folder " + path, &dlg ) );
              else
                  dlg.layout()->addWidget( new QLabel( "Could NOT create folder " + path, &dlg ) );
          }
          else
          {
              dlg.layout()->addWidget( new QLabel( "Folder exists " + path, &dlg ) );
          }
      
          path += "/from_qt.txt";
      
          QFile file(path);
          if (file.open(QIODevice::ReadWrite))
          {
              QTextStream stream(&file);
              stream << "something" << endl;
              dlg.layout()->addWidget( new QLabel( "Could create file " + path, &dlg ) );
          }
          else
          {
              dlg.layout()->addWidget( new QLabel( "Could NOT create file " + path, &dlg ) );
          }
      
          dlg.show();
          return a.exec();
      }
      
      
      

       

      Compiled using Qt 5.14.2 and Android NDK r21b with QtCreator 4.12.0 reports that file cannot be created.

      The AndroidManifest.xml file cretaed through QtCreator has both android.permission.READ_EXTERNAL_STORAGE and android.permission.WRITE_EXTERNAL_STORAGE set.
       
      This used to perfectly work with Qt 5.12.0 and Andoird NDK r18b.

      By the way, when installing the app compiled with 5.14.2, Android reports that the app does not requests for any privileges. While when installing the one compiled with 5.12.0, it reports app needs to access external storage. So looks like android permissions and not correctly set in the apk?

      Attachments

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

        Activity

          People

            qtandroidteam Qt Android Team
            jpo38 Jean Porcherot
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes