如何在Linux中检测到USB驱动器插入? [英] How do I detect usb drive insertion in Linux?

查看:383
本文介绍了如何在Linux中检测到USB驱动器插入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为嵌入式Linux项目编写了一个应用程序,并且我希望我的应用程序在用户插入USB驱动器时显示特定的菜单.我正在用Qt用C ++编写应用程序.

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. I'm programming the application in C++ with Qt.

我的系统没有d-bus,但是正在使用udev.在我看来,udev是执行此检测的正确"方法,但似乎很复杂.

My system doesn't have d-bus but it is using udev. It seems to me that udev is the "proper" way to do this detection, but seems complicated.

有人能指出我正确的方向来开始这一工作吗?没有udev,有没有办法做到?如果没有,是否有我可以使用的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? 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).

谢谢

马龙

推荐答案

本文档的"libudev-监视界面"部分 http://www.signal11.us/oss/udev/ 应该可以帮助您开始.
代替while(1)循环和睡眠,只需使用该东西创建一个函数,然后设置一个定期的Qt计时器,每隔半秒或更长时间调用一次即可.

The section "libudev - Monitoring Interface" of this document http://www.signal11.us/oss/udev/ should get you started.
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.

这篇关于如何在Linux中检测到USB驱动器插入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆