问题
I want linux to inform my Qt program by a signal when a particular USB device is connected. Storage devices like flash disk or hard drive. How can I do this? What are your suggestions?
UPDATE:
I have found that QtDbus can provide the functionality that I need but I have not figure out how exactly. Is there anyone can give information about getting USB device notification with QtDbus?
I have been reading this tutorial:
http://dbus.freedesktop.org/doc/dbus-tutorial.html
This tutorial says:
D-Bus is designed for two specific cases:
- Communication between desktop applications in the same desktop session; to allow integration of the desktop session as a whole, and address issues of process life-cycle (when do desktop components start and stop running).
- Communication between the desktop session and the operating system, where the operating system would typically include the kernel and any system daemons or processes.
I am planning to use this facility which I am asking for help in a non-graphical Linux system. More precisely on Beagleboard-XM with Angstrom Linux console image with QWS.
In this circumstances does QtDbus is a correct choice?
回答1:
Haven't tried Qt's DBUS implementation, but the general details of how to get a USB notification are in this tutorial
The QtDBus function names probably map onto these fairly easily
回答2:
You might want to take a look with qdbusviewer from qt4-dev-tools what kind of dbus interface your system has regarding device notification (be it HAL or udev). Than it is relatively simple to generate a c++ implementation with qdbusxml2cpp. You will just have to connect to whatever dbus signal your system is suppling for device notification purposes. Here is a quick start guide for qt and dbus QtDbus Tutorual.
来源:https://stackoverflow.com/questions/8604081/can-linux-signal-my-qt-program-when-a-particular-usb-device-is-connected