Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Problem with QDirIterator on android
QtWS25 Last Chance

Problem with QDirIterator on android

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
5 Posts 3 Posters 338 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    modelvincent
    wrote on last edited by
    #1

    Hi,

    I'm developping a Qt Android app that need to store some files in the shared memory of android so that the user can access those files when connected to a PC to copy/paste the files.

    I've transferred some file from my computer (windows) to this folder, I see the files from windows explorer and from android explorer, but no way to display my files.

    Here is my folder as seen from windows explorer. I have different files extensions.

    07fe747a-77e7-4f1c-87ba-a6a184b99417-image.png

    In my listFilter, I've tried ".modele", ".jpg", ".", ".modele" and even tried "*"

    • all image format are correctly detected (even if I rename one of my .modele to .jpg or .bmp, it is working
    • more strange: if I create the file from my application, it is correctly detected, but if I launch another code on the same directory, this time it is not detected

    Here is my code (don't worry about some redondant variables such as directory, CheminComplet and directoryPath, I've reduced my code to be easier to share, but this code has the same behaviour.

    TestEcriture::TestEcriture(QWidget *parent)
        : QWidget(parent)
        , ui(new Ui::TestEcriture)
    {
        ui->setupUi(this);
    
    
        QString CheminComplet;
    
        bool result;
        QDir dir("/storage/emulated/0/Documents/");
        result = dir.mkdir("FichiersModelManager");
    
        CheminComplet = dir.path() + "/FichiersModelManager/";
        qDebug() << "Working folder: " << CheminComplet;
    
    
        QString directory = CheminComplet;
    
        if (!directory.isEmpty()) {
            qDebug() << "Selected directory :" << directory;
    
        } else {
            qDebug() << "Aucun répertoire sélectionné.";
        }
    
    
    
    
        QString directoryPath= CheminComplet;
        qDebug() << "in function, we will use path: " << directoryPath;
        QStringList listFilter;
        listFilter << "*";
    
        QDirIterator dirIterator(directoryPath,listFilter, QDir::Files, QDirIterator::NoIteratorFlags);
        qDebug() << "dirIterator: " << dirIterator.path();
    
        QStringList fileList;
        QDir dirTest(directoryPath);
        qDebug() << dirTest.entryList() << dirTest.entryInfoList();
    
        while(dirIterator.hasNext())
        {
            qDebug() << "DirIterator.next(): " << dirIterator.next();
            qDebug() << dirIterator.fileName() << dirIterator.fileName().remove(".modele");
        }
    }
    

    I precise that I have activate the rights for read and writing files in android manifest

    I must admit that I am completely lost...

    Thanks for your help,

    Vincent

    jsulmJ J.HilkJ 2 Replies Last reply
    0
    • M modelvincent

      Hi,

      I'm developping a Qt Android app that need to store some files in the shared memory of android so that the user can access those files when connected to a PC to copy/paste the files.

      I've transferred some file from my computer (windows) to this folder, I see the files from windows explorer and from android explorer, but no way to display my files.

      Here is my folder as seen from windows explorer. I have different files extensions.

      07fe747a-77e7-4f1c-87ba-a6a184b99417-image.png

      In my listFilter, I've tried ".modele", ".jpg", ".", ".modele" and even tried "*"

      • all image format are correctly detected (even if I rename one of my .modele to .jpg or .bmp, it is working
      • more strange: if I create the file from my application, it is correctly detected, but if I launch another code on the same directory, this time it is not detected

      Here is my code (don't worry about some redondant variables such as directory, CheminComplet and directoryPath, I've reduced my code to be easier to share, but this code has the same behaviour.

      TestEcriture::TestEcriture(QWidget *parent)
          : QWidget(parent)
          , ui(new Ui::TestEcriture)
      {
          ui->setupUi(this);
      
      
          QString CheminComplet;
      
          bool result;
          QDir dir("/storage/emulated/0/Documents/");
          result = dir.mkdir("FichiersModelManager");
      
          CheminComplet = dir.path() + "/FichiersModelManager/";
          qDebug() << "Working folder: " << CheminComplet;
      
      
          QString directory = CheminComplet;
      
          if (!directory.isEmpty()) {
              qDebug() << "Selected directory :" << directory;
      
          } else {
              qDebug() << "Aucun répertoire sélectionné.";
          }
      
      
      
      
          QString directoryPath= CheminComplet;
          qDebug() << "in function, we will use path: " << directoryPath;
          QStringList listFilter;
          listFilter << "*";
      
          QDirIterator dirIterator(directoryPath,listFilter, QDir::Files, QDirIterator::NoIteratorFlags);
          qDebug() << "dirIterator: " << dirIterator.path();
      
          QStringList fileList;
          QDir dirTest(directoryPath);
          qDebug() << dirTest.entryList() << dirTest.entryInfoList();
      
          while(dirIterator.hasNext())
          {
              qDebug() << "DirIterator.next(): " << dirIterator.next();
              qDebug() << dirIterator.fileName() << dirIterator.fileName().remove(".modele");
          }
      }
      

      I precise that I have activate the rights for read and writing files in android manifest

      I must admit that I am completely lost...

      Thanks for your help,

      Vincent

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @modelvincent You're creating a new empty folder in TestEcriture::TestEcriture ("result = dir.mkdir("FichiersModelManager")")- why do you expect to see any files there?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      M 1 Reply Last reply
      0
      • jsulmJ jsulm

        @modelvincent You're creating a new empty folder in TestEcriture::TestEcriture ("result = dir.mkdir("FichiersModelManager")")- why do you expect to see any files there?

        M Offline
        M Offline
        modelvincent
        wrote on last edited by
        #3

        @jsulm
        This line just create the folder if it is not existing, but if it already exists, the function return fail but the program continue.

        It is working as i am able to list the jpg file

        Best regards

        Vincent

        1 Reply Last reply
        0
        • M modelvincent

          Hi,

          I'm developping a Qt Android app that need to store some files in the shared memory of android so that the user can access those files when connected to a PC to copy/paste the files.

          I've transferred some file from my computer (windows) to this folder, I see the files from windows explorer and from android explorer, but no way to display my files.

          Here is my folder as seen from windows explorer. I have different files extensions.

          07fe747a-77e7-4f1c-87ba-a6a184b99417-image.png

          In my listFilter, I've tried ".modele", ".jpg", ".", ".modele" and even tried "*"

          • all image format are correctly detected (even if I rename one of my .modele to .jpg or .bmp, it is working
          • more strange: if I create the file from my application, it is correctly detected, but if I launch another code on the same directory, this time it is not detected

          Here is my code (don't worry about some redondant variables such as directory, CheminComplet and directoryPath, I've reduced my code to be easier to share, but this code has the same behaviour.

          TestEcriture::TestEcriture(QWidget *parent)
              : QWidget(parent)
              , ui(new Ui::TestEcriture)
          {
              ui->setupUi(this);
          
          
              QString CheminComplet;
          
              bool result;
              QDir dir("/storage/emulated/0/Documents/");
              result = dir.mkdir("FichiersModelManager");
          
              CheminComplet = dir.path() + "/FichiersModelManager/";
              qDebug() << "Working folder: " << CheminComplet;
          
          
              QString directory = CheminComplet;
          
              if (!directory.isEmpty()) {
                  qDebug() << "Selected directory :" << directory;
          
              } else {
                  qDebug() << "Aucun répertoire sélectionné.";
              }
          
          
          
          
              QString directoryPath= CheminComplet;
              qDebug() << "in function, we will use path: " << directoryPath;
              QStringList listFilter;
              listFilter << "*";
          
              QDirIterator dirIterator(directoryPath,listFilter, QDir::Files, QDirIterator::NoIteratorFlags);
              qDebug() << "dirIterator: " << dirIterator.path();
          
              QStringList fileList;
              QDir dirTest(directoryPath);
              qDebug() << dirTest.entryList() << dirTest.entryInfoList();
          
              while(dirIterator.hasNext())
              {
                  qDebug() << "DirIterator.next(): " << dirIterator.next();
                  qDebug() << dirIterator.fileName() << dirIterator.fileName().remove(".modele");
              }
          }
          

          I precise that I have activate the rights for read and writing files in android manifest

          I must admit that I am completely lost...

          Thanks for your help,

          Vincent

          J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by
          #4

          @modelvincent you're actually not supposed to access the phones storage as a regular app.

          You will either have to

          • root your device
          • only use old and outdated android versions
          • register your app as a file manager app

          You have to implement FileSharing if you're going the regular route. Meaning you send/share your file via the standard file browser to your application, as a mandatory user interaction


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          1 Reply Last reply
          0
          • M Offline
            M Offline
            modelvincent
            wrote on last edited by
            #5

            So there is no easy way to create files in the app and retrieve them on a PC, or reverse? create files on PC and transfer them to the phone to uses them in the app?

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved