2010-12-13 20 views
3

首先请让我解释什么,我试图做的:Qt编程:串口通信模块/插件

  1. 我使用Qt来构建主要是基于WebKit的应用程序。这个应用程序从互联网获取内容,并通过传统的网络方式呈现给用户。

  2. 我的应用程序有许多沟通串口设备,如打印机,IC卡读卡器。

  3. 这些串口设备有不同的型号,所以它们有不同的通信协议。

  4. 我想我的应用程序和串口设备communcating部分分开,使我只能更新不更新所有的应用程序的通信电子部分。

我是否需要编写一个Qt插件/ webkit插件或其他方式来执行此操作?欢迎任何建议!

感谢

回答

0

串行端口部分qextserialport

+0

我已经准备好在我的应用程序。我的问题是如何使它成为模块/插件 – 2010-12-13 02:53:12

+0

虽然这个链接可能回答这个问题,但最好在这里包含答案的基本部分并提供供参考的链接。如果链接页面更改,则仅链接答案可能会失效。 – Matthieu 2012-08-17 21:50:24

+0

@Matthieu就像它指向的图书馆一样! – 2012-08-17 22:32:53

0

构建使用TARGET = lib和CONFIG + = DLL在另一个QMAKE文件中的一个dll /动态库的通信部分。

0

我会建议使用C++的PluginManager样式插件方法之一。

我从2+岁的内存,所以它仅作为一个松散的指南,而不是一个明确的答案写这个。

我已经包含了一个link到我使用的网站上一个项目,就像你在几年前形容上手。它可以与我们提供的40多个插件配合使用。

一种[DLL插件的C++类]搜索应该找到几个网站给你的,如果你不喜欢我联系的人。

你必须正确地为你的环境/编译器/ OS等

从本质上说,假设你想打开,读取,写入和你的插件关闭串口的能力。

创建一个纯虚基类(充当声明为Java中的接口的东西):

 
/* This is the basic plugin header file that every plugin DLL has to include 

    Use your compilers pragmas/keywords to export the entire class from the DLL 
    In Microsoft land the keywords are _declspec(dllexport) to export the class 
    from the base DLL and __declspec(dllimport) to import the class into other 
    code. I'm using the MS keywords here because I don't remember how this is done 
    in other compilers. :) 
*/ 

#if BUILDING_BASE_PLUGIN 
/* You're compiling the DLL that exports the Plugin Base 
#define BASE_DLL_EXPORT declspec(dllexport) 
#else 
/* You're compiling code that uses the plugin base 
#define BASE_DLL_EXPORT declspec(dllimport) 
#endif 

class DLL_EXPORT SerialPortPluginBase 
{ 
public: 
    enum SerialPortPluginError{ SUCCESS = 0, ERROR_1, ERROR_2, ERROR_ETC }; 

    virtual SerialPortPluginError Open(/*Parameters*/) = 0; 
    virtual SerialPortPluginError Read(/*Parameters*/) = 0; 
    virtual SerialPortPluginError Write(/*Parameters*/) = 0; 
    virtual SerialPortPluginError Close(/*Parameters*/) = 0; 
    static std::string pluginName = "SerialPortPluginBase"; 
    static int version; 
}; 

在每个插件,执行基于上述类以及注册/取消注册一个方法的界面带有插件管理器的DLL(请参阅下面的链接)。

每个插件都应该放在单独的DLL/SO中。

查看this site的完整示例。

希望这会有所帮助。 :)

3

AFAIK Qt已经提供了一个插件机制。

检查QLibrary类出来,那里的例子。

0

你想要的是创建一个Qt插件为您的应用程序:

http://doc.qt.io/archives/qt-4.7/plugins-howto.html

您可以通过插件来扩展你的主要应用。您需要添加到应用程序的唯一一件事是加载插件并添加一些事件来调用插件方法。