I've got a Qt application on an embedded arm processor running Wind River Systems GNU/Linux kernel (3.4.43-rt56-WR5.0.1.14_preempt-rt to be precise).

I am using the useful qdevicewatcher (https://github.com/wang-bin/qdevicewatcher) to detect when a USB flash drive is plugged in. That all works great and I get an event telling me that /dev/sda1 (for example) has just been added.

However, Qt cannot actually access folders/files on it, even though I can see that it is mounted through the shell.

I've got a couple of layers of event propagation (to filter out devices I don't care about), so for completeness, I will include both, but you can skip down for the interesting part. This first one (connected to the event from qdevice watcher) checks the device name, and the event is passed up to daddy for further consideration if it matches /dev/sda1.

Qt Code:
  1. void onDeviceAdded(const QString& dev)
  2. {
  3. if (dev == "/dev/sda1")
  4. {
  5. qDebug("tid=%#x %s: add %s", (quintptr)QThread::currentThreadId(), __PRETTY_FUNCTION__, qPrintable(dev));
  6. emit deviceAddedEvent();
  7. }
  8. }
To copy to clipboard, switch view to plain text mode 


Daddy's handler looks like this (now that I have loaded it up with qDebug messages...):

Qt Code:
  1. void Backend::onFlashAdded()
  2. {
  3. qDebug() << "onFlashAdded()";
  4. QString LOTDIR = "/media/sda1/LOT";
  5. QDir dir(LOTDIR);
  6. qDebug() << "Folder " << "/media" << " exists: " << QFile::exists("/media");
  7. qDebug() << "Folder " << "/media/sda1" << " exists: " << QFile::exists("/media/sda1");
  8. if (dir.exists())
  9. {
  10. qDebug() << "LOT folder present";
  11. QStringList filters;
  12. filters << "*.LOT";
  13. dir.setNameFilters(filters);
  14. foreach ( QString file, dir.entryList(filters, QDir::Files) )
  15. {
  16. qDebug() << "LOT file: " << file;
  17. }
  18. }
  19. else
  20. qDebug() << "Folder name " << LOTDIR << " exists: " << dir.exists();
  21.  
  22. emit flashAdded();
  23. }
To copy to clipboard, switch view to plain text mode 

When I plug in the flash, I see /dev/sda1 being added:

tid=0x7407f460 event=65535 virtual bool HotplugWatcher::event(QEvent*): Add /dev/sda1

And in turn, onFlashAdded is called, but it cannot actually see /media/sda1, which is where the cursed thing is mounted.

onFlashAdded()
Folder /media exists: true
Folder /media/sda1 exists: false
Folder name "/media/sda1/LOT" exists: false

If I look from the shell, /media/sda1 does exist and is my flash drive, with content as expected:

eLab:/# ls /media/sda1
Back Up Your Files to the Cloud.pdf* SanDiskSecureAccess/
LOT/ System Volume Information/
RunSanDiskSecureAccess_Win.exe*


My application is running as root, and the paths are readable by all anyway.

eLab:/# ll /media
total 60
drwxr-xr-x 2 root root 16384 Dec 31 1969 boot/
drwxr-xr-x 2 root root 4096 May 29 2014 card/
drwxr-xr-x 2 root root 4096 May 29 2014 cf/
drwxr-xr-x 2 root root 4096 May 29 2014 hdd/
drwxr-xr-x 2 root root 4096 May 29 2014 mmc1/
drwxr-xr-x 2 root root 4096 May 29 2014 net/
drwxrwxrwt 2 root root 40 Oct 4 14:26 ram/
drwxr-xr-x 2 root root 4096 May 29 2014 realroot/
drwxr-xr-x 5 root root 16384 Dec 31 1969 sda1/
drwxr-xr-x 2 root root 4096 May 29 2014 union/

eLab:/# ll /media/sda1
total 16112
-rwxr-xr-x 1 root root 403851 Oct 25 2013 Back Up Your Files to the Cloud.pdf*
drwxr-xr-x 2 root root 16384 Oct 4 07:23 LOT/
-rwxr-xr-x 1 root root 16024600 Feb 5 2015 RunSanDiskSecureAccess_Win.exe*
drwxr-xr-x 2 root root 16384 Feb 24 2015 SanDiskSecureAccess/
drwxr-xr-x 2 root root 16384 Oct 4 07:23 System Volume Information/


Any ideas, anybody?