在Linux OS中使用Qt的USB连接事件 [英] USB connected event using Qt in Linux OS

查看:498
本文介绍了在Linux OS中使用Qt的USB连接事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个与USB设备交互的应用程序。我想在USB设备连接到系统时弹出一条消息。我怎么能用Qt做到这一点。当USB设备连接到系统时,是否还有其他库可用于触发事件。



当连接到新的USB设备时,我需要一个事件或插槽系统。

I am developing an application that will interact with USB devices. I want to pop up a message when a USB device is connected to the system. How can I do this using Qt. Is there any other library available to fire an event when a usb device is connected to the system.

I need an event or slot to when a new USB device connected to the system.

推荐答案

您正在寻找的库称为 INotify 。据我所知,它位于udev之上,并为您提供有关设备出现和消失的基于字符串的信息。我已经看到并使用代码来检测USB多串口的添加和删除,以便它可以满足您的需求。

接口只是我记忆中的C调用约定所以你从Qt代码中使用它没有问题。我不知道任何现有的Qt支持或Qt课程会为你加入这个问题,Qt4肯定没有。



一件建议,如果用户添加和删除设备,请将您的FDDI芯片序列号或购买/运送设备与其序列号。用户通常希望能够从一个USB端口移除一个设备并将其放入另一个USB端口,以便他们自己方便,并假设该软件将知道他们已经完成的工作并将设备视为旧设备返回不是新的。这可能非常棘手,因为udev和INotify不会提供任何自动支持此功能的内容。
The library you''re looking for is called INotify. As far as I know it sits on top of udev and gives you string based information about devices appearing and disappearing. I have seen and worked with code using it to detect the addition and removal of USB multi serial ports so it will do what you need.
The interface is just C calling convention from what I remember so you''ll have no problem using it from Qt code. I''m not aware of any exisitng Qt support or Qt classes that would interect with this for you, there certainly weren''t any in Qt4.

One piece of advice, if devices are being added and removed by users, get your FDDI chips serial numbered or buy/ship devices with them serial numbered. Users often expect to be able to remove a device from one USB port and put it in another for their own convinience and assume that the software will know that''s what they''ve done and treat the device as the old one come back not a new one. This can be really tricky as udev and INotify doen''t offer anything that automatically supports this.


这篇关于在Linux OS中使用Qt的USB连接事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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