有没有用于检测USB事件(插入和删除)的Qt解决方案? [英] Is there a Qt solution for detecting USB events (insertion and removal)?

查看:1156
本文介绍了有没有用于检测USB事件(插入和删除)的Qt解决方案?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于其他人在几年前已经问过,我想在Pendrive / datatraveler插入时,以及在我的系统中(在Linux Ubuntu和Embedded Linux中)拔掉电源时,都可以在Qt应用程序中进行检测。

As some other people already asked here some years ago, I want to be able to detect in a Qt application when a pendrive/datatraveler is plugged and when it is unplugged in my system (both in Linux Ubuntu and Embedded Linux).

我在SO中搜索,我注意到大多数答案不仅非常过时(例如从2010年),但所有解决方案以某种方式涉及非Qt解决方案问题:平台特定或使用外部库,如udev和DBus。

I searched in SO and I noticed that most answers not only were very outdated (from 2010 for example), but all solutions somehow involved "non-Qt solutions" to these problem: either platform specific or usage of external libraries such as udev and DBus.

我想知道的首先是如果有一个特定的Qt解决方案,即一个这样做,而不需要添加外部libs或平台特定的代码,如何使用它。优先地,它应该已经在Qt 4.8。如果没有Qt解决方案,则可以接受基于Qt的库。

What I want to know first of all is if there is a specific Qt solution for this, i.e. a way to do this without requiring adding external libs or platform specific codes, and how could I use it. Preferentially it should already be available in Qt 4.8. If there is no Qt solution, then a Qt-based library would be acceptable.

添加:搜索结果:

  • USB Programming with Qt: Suggests libusb and WinUSB API
  • Detecting USB notification in Qt on windows: Windows only
  • How do I detect usb drive insertion in Linux?: Suggests libudev
  • How to get USB notifications under linux / Qt?: Suggests DBus
  • How to know when a new USB storage device is connected in Qt?: Windows only
  • How to detect USB device disconnect under Linux/Qt/C++: Linux only, suggests HAL, DeviceKit and udev
  • Is there a C++ cross platform USB library?: Suggests libusbx

推荐答案

如前所述, Qt 模块。然而,有一个用户创建的类<​​code> QDeviceWatcher 。

As already pointed out, Qt itself does not provide such a module. There is however a user-made class called QDeviceWatcher. I have no experience with it personally and it is not updated regularly but you could give it a try.

你可以找到论坛帖子此处和git存储库此处

You can find the forum post here and the git repository here.

这篇关于有没有用于检测USB事件(插入和删除)的Qt解决方案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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