Qt编程:串口通信模块/插件
首先请让我解释一下我想要做什么:
我正在使用 Qt 构建一个主要基于 webkit 的应用程序。这个应用程序从互联网上获取内容并通过传统的Web方式将其呈现给用户。
我的应用程序需要与许多串口设备进行通信,例如打印机、IC卡读卡器。
这些串口设备具有不同的型号,从而具有不同的通信协议。
我想将我的应用程序与串口设备通信部分分开,这样我只能更新通信部分而不更新所有应用程序。
我需要编写 Qt 插件/webkit 插件,还是其他方式来执行此操作?欢迎任何建议!
谢谢
Firstly please let me explain what I am trying to do:
I am using Qt to build an app mainly based on webkit. This app fetches content from internet and present it to user by traditional web way.
My app has to communicate many serial port devices, such as printer, IC card reader.
These serial port devices have different models, so that they have different communication protocol.
I want separate my app with the serial port devices communcating part, so that I can only update the communcation part without updating all the app.
Do I need to write a Qt plugin/webkit plugin, or some other way to do this? Any suggestions are welcome!
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
AFAIK Qt 已经提供了插件机制。
检查 QLibrary 类及其示例。
AFAIK Qt already provides a plugin mechanism.
Check the QLibrary class out and the examples there.
对于串口部分qextserialport
For the serial port part qextserialport
通过在另一个 qmake 文件中使用 TARGET = lib 和 CONFIG += dll 在 dll/动态库中构建通信部分。
Build your communication part in a dll/dynamic library by using TARGET = lib and CONFIG += dll in another qmake file.
我建议使用 C++ 的 PluginManager 风格插件方法之一。
我是根据 2 岁多的记忆写下这篇文章的,所以它只是作为一个松散的指南,而不是一个明确的答案。
我添加了一个链接我曾经开始一个像你几年前描述的项目的网站。它与我们可用的 40 多个插件配合得很好。
如果您不喜欢我链接的网站,搜索 [DLL 插件 C++ 类] 应该可以找到几个适合您的网站。
您必须针对您的环境/编译器/操作系统等进行更正。
本质上,假设您希望能够在插件中打开、读取、写入和关闭串行端口。
创建一个纯虚拟基类(充当 Java 中声明为接口的东西):
在每个插件中,实现基于上述类的接口以及使用插件管理器注册/取消注册 DLL 的方法(请参阅下面的链接) )。
每个插件应该放在单独的 DLL/SO 中。
有关完整示例,请参阅此网站 。
希望这有帮助。 :)
I would suggest one of the PluginManager style plugin methods with C++.
I'm writing this from 2+ year old memory so it's meant only as a loose guide, not a definitive answer.
I have included a link to a site I used to get started on a project like you describe a few years ago. It worked well with the 40+ plugins we had available.
A search for [DLL plugin C++ class] should find several of the sites for you if you don't like the one I linked.
You will have to correct for your environment/compiler/OS etc.
In essence, assume you want the ability to Open, Read, Write and Close the serial ports in your plugins.
Create a pure virtual base class (Acts as something declared as an interface in Java):
In each plugin, implement the interface based on the above class as well as a method to register/unregister the DLL with a plugin manager (see the link below).
Each plugin should go in a separate DLL/SO.
See this site for a complete example.
Hope this helps. :)
您想要的是为您的应用程序创建一个 Qt 插件:
http:// doc.qt.io/archives/qt-4.7/plugins-howto.html
您将能够通过插件扩展您的主应用程序。您需要添加到应用程序中的唯一事情是加载插件的过程并添加一些事件来调用插件方法。
What you want is to create a Qt Plugin for your application:
http://doc.qt.io/archives/qt-4.7/plugins-howto.html
You'll be able to extend your main application through a plugin. The only thing you'll need to add to your application is the process of load plugins and add some events to call plugins methods.