How to detect inserted USB

谁说我不能喝 提交于 2019-12-12 06:00:55

问题


In Qt Application I've developed to run on an embedded ARM-based system, I have to detect when USB pendrive has been inserted and what it contains, since I'd like to show contained files on a windows and allow the user to choice one of them. In order I have to:

  1. detect when USB is inserted;
  2. USB identification;
  3. USB file contained in.

Try to explain: I have a file to save and restore in an external device. It contains some settings related to my app developed using Qt for an embedded system (based on ARM microcontroller). I'm already done tyhe same for SD card, because I know exactly what kind of device will be opened, its path, its name etc. Problem exist if I wanna do the same using a USB pendrive, since every one has its own name. Thus I don't know firstly its path (I supposed "/media/myusername", i.e. where I found my USB when it's inserted), and how to open it. I'm starting making some trials using the QFileSystemWatcher library: I connect the directoryChanged Signal to a slot that shows me folder. It works, but it's not enough to proceed further. Any solution?

How to do this?


回答1:


the normal way to get notification about attached usb devices is over udev either using udevadm (udevadm monitor | grep ...) , libudev or udev rules

http://www.signal11.us/oss/udev/

https://unix.stackexchange.com/questions/116536/usb-connect-disconnect-notification

Can linux signal my Qt program when a particular USB device is connected?

https://askubuntu.com/questions/27948/usb-device-changes-using-udev-and-d-bus

HAL is deprecated in linux... http://madison-project.wdfiles.com/local--files/tutorials/Hal_Tutorial.pdf linux hotplugging



来源:https://stackoverflow.com/questions/33912965/how-to-detect-inserted-usb

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!