Problem with QDirIterator on android
-
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.
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
-
@modelvincent You're creating a new empty folder in TestEcriture::TestEcriture ("result = dir.mkdir("FichiersModelManager")")- why do you expect to see any files there?
-
@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
-
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?