2

I'm using QtCreator and Qt for android.
I was trying to make a file dialog app on android,using QFileSystemModel.
And I'm debugging on my phone(HTC A9).

I can't see any other content on my phone except my package(QDir::currentPath()) but if I set to QDir::rootPath(), the file dialog shows nothing but / at beginning(nothing after I try to access it)

The console shows :

W libFileDialog.so: (null):0 ((null)): inotify_add_watch("/data/user") failed: "Permission denied"
W libFileDialog.so: (null):0 ((null)): inotify_add_watch("/data") failed: "Permission denied"
W libFileDialog.so: (null):0 ((null)): inotify_add_watch("/") failed: "Permission denied"
W libFileDialog.so: (null):0 ((null)): inotify_add_watch("/data") failed: "Permission denied"
W libFileDialog.so: (null):0 ((null)): inotify_add_watch("/data/user") failed: "Permission denied"
W libFileDialog.so: (null):0 ((null)): inotify_add_watch("/data/user/0") failed: "Permission denied"

I added permissions

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

But it still says inotify_add_watch failed blahblah...
And it works totally fine on windows. And if I use virtual device to debug, it still denies sometimes but only denies permission when I try to set the root path of the model to some directory called (date, config... etc)
How should I fix that?
Or is it the problem about coding an android app with only C++ so it's telling me to go to learn JAVA?( I really want to stick to C++ :c )

code:

_fileModel = new QFileSystemModel;
_fileModel->setReadOnly(false);
_fileModel->setRootPath(QDir::rootPath());
_fileModel->setFilter(QDir::NoDotAndDotDot | QDir::AllDirs | QDir::Files);
ui->listView->setModel(_fileModel);  

I just read that after I need to request permission while running.


I called static java method to request permissions, and it's granted, but I still can't see the files. (only difference is that I can see /sdcard inside my virtual device.)

LittleMerryn
  • 45
  • 1
  • 7
  • This looks like fundamental filesystem permissions. Your process's PID does not have read permissions on the directories in question. – Sam Varshavchik Aug 27 '17 at 13:37

1 Answers1

1

I have experience with inotify and FileObserver but not with Qt. But some things are global, as Sam said you do not have permissions to root. This is an OS protection, it might work sometimes if you have root access, which might be the case on your windows emulator (if I understood correctly). You should not rely on having root access and your application is limited to its own internal memory and the external memory which can be found as explaind here.

In any case to answer your question, you do not need to learn java, FileObserver is just a wrapper to the inotify api which is an OS (linux) api.

Eytan
  • 728
  • 1
  • 7
  • 19