如何在我的 qt 应用程序中收到有关 USB 驱动器插入系统的通知
我正在 Ubuntu 10.04 上的 Qt 4.6/4.7 中编写一个应用程序,其中我需要在 USB 驱动器连接到系统时从它复制一些文件。应用程序在运行时应该能够检测到笔式驱动器已插入,并且无需用户干预,应该在 USB 驱动器中查找特定文件并将其复制到本地驱动器。每次插入新的笔式驱动器时都会发生这种情况。有什么我可以使用的简单方法吗?请建议。
预先感
谢马赫什
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
Mahesh
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
考虑热插拔机制。通过热插拔,内核会在硬件更改其状态时发送事件。通常监听事件意味着使用
/sbin/hotplug
脚本,但也提供了一个 netlink 套接字。这样你就可以监听套接字,过滤所需的事件并处理它们。这里是一个文档,您可以找到详细的解释和 C 代码示例。
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.
您应该使用 udev 服务并定义一个触发器,该触发器将根据插入设备的属性启动您的应用程序。
You should use udev service and define a trigger which will launch your app depending on attributes of plugged device.