如何在我的 qt 应用程序中收到有关 USB 驱动器插入系统的通知

发布于 2024-10-06 10:34:38 字数 205 浏览 0 评论 0原文

我正在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

晨曦÷微暖 2024-10-13 10:34:38

考虑热插拔机制。通过热插拔,内核会在硬件更改其状态时发送事件。通常监听事件意味着使用 /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.

城歌 2024-10-13 10:34:38

您应该使用 udev 服务并定义一个触发器,该触发器将根据插入设备的属性启动您的应用程序。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文