QDeviceWatcher-Make hotplug detection easy
-
It's my project: https://github.com/wang-bin/qdevicewatcher
Just need QtCore module.
It works fine on linux and windows. I have tested on my ubuntu and win7. Usually you just need the signals @deviceAdded(const QString& device)@ and @deviceRemoved(const QString& device)@ in QDeviceWatcher.To detect the device changes, i use netlink in linux(kernel 2.6) and internel window in windows.
In windows, I tried two method,
@virtual bool QCoreApplication::winEventFilter(MSG* msg, long* result)
//and
virtual bool QWidget::winEvent(MSG* msg, long* result)@
I hope my class is just a subclass of QObject, and do not use GUI module, so I started to find other ways. At last I refer to qdrive project: https://gitorious.org/qdrive/qdrive
In qdrive project, it watch /etc/mtab in linux, but some systems will not mount new disk, so I use netlink.
This class is only for watching hotplug events now. You can deal with the device yourself, e.g. mount and umount the device.
!http://qt-apps.org/CONTENT/content-pre1/145200-1.png(windows)!
!http://qt-apps.org/CONTENT/content-pre2/145200-2.png(ubuntu)!
EDIT: moved to showcase, Gerolf