Results 1 to 3 of 3

Thread: QDir not seeing directories on automounted flash drive (GNU/Linux)

  1. #1
    Join Date
    Jan 2014
    Posts
    2
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default QDir not seeing directories on automounted flash drive (GNU/Linux)

    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?

  2. #2
    Join Date
    Jan 2014
    Posts
    2
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QDir not seeing directories on automounted flash drive (GNU/Linux)

    The answer: add a delay before trying to access folders/files on the drive. I had already tried a one second delay, but evidently that was not enough.

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QDir not seeing directories on automounted flash drive (GNU/Linux)

    Or watch /media with a QFileSystemWatcher?

    Cheers,
    _

Similar Threads

  1. QDir, list all directories?
    By hakermania in forum Newbie
    Replies: 10
    Last Post: 1st July 2015, 06:41
  2. Return number of directories in a directories
    By franco.amato in forum Newbie
    Replies: 7
    Last Post: 30th September 2010, 00:29
  3. Flash Player Crashes in linux platform
    By Peter Jerald in forum Qt Programming
    Replies: 1
    Last Post: 6th July 2010, 09:54
  4. QDir::entryList() on linux
    By JeanC in forum Qt Programming
    Replies: 3
    Last Post: 3rd March 2008, 14:46
  5. Replies: 10
    Last Post: 4th December 2006, 06:38

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.