Euzao
13th August 2011, 12:41
I'll try to be brief:
My program should automatically sense when a USB device is plugged and also where that device was mounted. So far I've been able to sense the usb device plugged, as well as getting which device was inserted (i.e. /dev/sdc1).
Knowing the device (i.e. /dev/sdc1) I can then simply look inside /etc/mtab to match that device with its mount point (i.e. /media/USBDRIVE). However when I try to find that device inside /etc/mtab, I get nothing, but if I tell the program to wait 1 second before trying to search inside /etc/mtab, it works, meaning my program was actually trying to find the device before it was actually added to /etc/mtab
So what I did was instead of waiting 1 second to search in /etc/mtab, I created a QFileSystemWatcher for that file:
QFileSystemWatcher watcher = new QFileSystemWatcher(QStringList() << "/etc/mtab",this);
But watcher never detects any change in /etc/mtab! Even if try /proc/mounts which is the same file... What is weird is that for any file inside /home, QFileSystemWatcher will work, but for /etc or /proc files it won't work.
I will thank you guys for any help, since the 1 second wait is not the best approach..
My program should automatically sense when a USB device is plugged and also where that device was mounted. So far I've been able to sense the usb device plugged, as well as getting which device was inserted (i.e. /dev/sdc1).
Knowing the device (i.e. /dev/sdc1) I can then simply look inside /etc/mtab to match that device with its mount point (i.e. /media/USBDRIVE). However when I try to find that device inside /etc/mtab, I get nothing, but if I tell the program to wait 1 second before trying to search inside /etc/mtab, it works, meaning my program was actually trying to find the device before it was actually added to /etc/mtab
So what I did was instead of waiting 1 second to search in /etc/mtab, I created a QFileSystemWatcher for that file:
QFileSystemWatcher watcher = new QFileSystemWatcher(QStringList() << "/etc/mtab",this);
But watcher never detects any change in /etc/mtab! Even if try /proc/mounts which is the same file... What is weird is that for any file inside /home, QFileSystemWatcher will work, but for /etc or /proc files it won't work.
I will thank you guys for any help, since the 1 second wait is not the best approach..