简体   繁体   English

如何检测Linux中的USB驱动器插入?

[英]How do I detect usb drive insertion in Linux?

I've written an application for an embedded linux project, and I want my application to display a particular menu when the user inserts a USB drive. 我已经编写了一个嵌入式Linux项目的应用程序,我希望我的应用程序在用户插入USB驱动器时显示一个特定的菜单。 I'm programming the application in C++ with Qt. 我用Qt用C ++编写应用程序。

My system doesn't have d-bus but it is using udev. 我的系统没有d-bus,但它使用的是udev。 It seems to me that udev is the "proper" way to do this detection, but seems complicated. 在我看来,udev是进行这种检测的“正确”方式,但似乎很复杂。

Can anyone point me in the right direction to get started with this? 任何人都可以指出我正确的方向来开始这个? Is there a way to do it without udev, and if not, is there a good "getting started" guide for udev I could use? 有没有办法没有udev,如果没有,是否有一个很好的“入门”指南udev我可以使用? I really don't need much functionality, just a way for my application to be notified when a drive is inserted (and enough info for my app to mount the drive). 我真的不需要太多功能,只是一种方式可以让我的应用程序在插入驱动器时得到通知(以及我的应用程序安装驱动器的足够信息)。

Thanks 谢谢

Marlon 马龙

The section "libudev - Monitoring Interface" of this document http://www.signal11.us/oss/udev/ should get you started. 本文档http://www.signal11.us/oss/udev/的 “libudev - Monitoring Interface”部分可以帮助您入门。
Instead of a while(1) loop and a sleep, just make a function with that stuff and then set up a periodic Qt timer to call it every half second or whatever. 而不是while(1)循环和睡眠,只需用这些东西创建一个函数,然后设置一个周期性的Qt计时器,每隔半秒或其他任何时候调用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM