Qt detection USB flash drive insertion

Source: Internet
Author: User
The solution has been found. The following describes the most important part. The other part is not difficult. The problem mainly lies in how to find the USB flash drive insertion and dial-out, which can be achieved using the q6. The following is the connection. Code When a device is inserted, you can call the slotdeviceadded (qstring UDI) function.

In the pro file, add
Qt + = Success

Copy code

1. # include <qtdbus/qdbusconnection>
2. // The following is the insertion of the detection device.
3. qdbusconnection: systembus (). Connect ("org. freedesktop. Hal ",
4. "/org/freedesktop/hal/manager ",
5. "org. freedesktop. Hal. Manager ",
6. "deviceadded ",
7. This,
8. Slot (slotdeviceadded (qstring )));
9. // The following is the dial-out of the check device.
10. qdbusconnection: systembus (). Connect ("org. freedesktop. Hal ",
11. "/org/freedesktop/hal/manager ",
12. "org. freedesktop. Hal. Manager ",
13. "deviceremoved ",
14. This,
15. Slot (slotdeviceremoved (qstring )));

In the slotdeviceadded (qstring UDI) function

Copy code

1. qdbusinterface device ("org. freedesktop. Hal", Udi, "org. freedesktop. Hal. device", qdbusconnection: systembus ());

You can use Hal to query the volume device, and then determine whether it is a/dev/SD * device. Then you can determine whether it is a USB flash disk, and then call Mount.
At this time, record the UDI of the USB flash disk. when the device is detected to dial out, check whether the UDI of the USB flash disk is still there and check whether the USB flash disk is dropped out.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.