2010-12-13 21 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

您可以通過插件來擴展你的主要應用。您需要添加到應用程序的唯一一件事是加載插件並添加一些事件來調用插件方法。