开发者

How do I get notified in my qt application about USB drive plugged in to the system

I am writing an application in Qt 4.6/4.7 on Ubuntu 10.04 where in I need to copy some files from the USB drive the moment it is connected to the system. The application while it is running, should be able to detect that a pen drive is inserted and without the user intervention, should look into the usb drive for specific file and copy it to the local drive. This should happen every time a new pen drive is inserted. is there any simple method which i can use? Pls suggest.

Thanks in advance

Ma开发者_开发知识库hesh


Consider the hotplug mechanism. With the hotplug the kernel sends events when hardware changes its state. Usually listening to the events implies the use of the /sbin/hotplug script, but a netlink socket is also provided. So you can listen to the socket, filter required events and handle them.

Here is a doc you can find a detailed explanation and a C code example.


You should use udev service and define a trigger which will launch your app depending on attributes of plugged device.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜