[Solved .. kind of] Getting event when USB is attached/detached
-
Does somebody know this? http://sourceforge.net/projects/qdevicewatcher/
-
If you have udisks running on the embedded system then you could use QDbus to get events.
-
Do you have udev running ?
-
IIRC, not all filesystems on linux can be watched, thinking of /dev and /sys if my memory serves well. However, you could also simply poll dev for known device, not really efficient but might be simpler
-
Setting a watcher on /dev works as supposed.
Plugging a USB memory stick adds 5 entries in /dev which are removed again if the device is unplugged. The directoryChanged signal is emitted 17 times for plugging and 5 times for unplugging.
However, since the signal does not contain the information of what exactly the change in /dev was, I would need to maintain a list of the contents of /dev to be able to compare ... /dev has about 150 entries ... doing this for every emit ... I'm not sure if this is a good idea nor do I already have a solid idea on a efficient solution for doing this. -
You could keep a list of /dev's content when starting to watch and then compare it to the current content when getting the directoryChanged signal. You can couple that with a QTimer to avoid a burst of your slot
-
Just did a test to debug output with this solution which could be a starting point to work something out:
@void QTGUI_MainWindow::showModifiedDirectory(QString directory)
{
qDebug() << "directory changed:" << directory;
QDir dir(directory);
if(dir.exists("sda1")) { qDebug() << "sda1 found!"; }
if(dir.exists("sdb1")) { qDebug() << "sdb1 found!"; }
}
@ -
There is a "a device watcher":http://qt-project.org/forums/viewthread/9605/ library.
I have not tried it.