2013-01-02 92 views
0

我需要使用某些函數創建基於Qt的動態庫,例如GetValue。 這個函數應該用QLineEdit調用對話框並返回輸入值。 我創建了沒有Qt類的結構。源代碼編譯成功,我得到的DLL。Qt在庫中使用QApplication

但是,當我加入Qt的對象,我得到鏈接錯誤是這樣的:

guilib2.obj:錯誤LNK2019:無法解析的外部符號「__declspec(dllimport的)市民:虛擬_ thiscall的QApplication ::〜QApplication的(無效) 「( _imp _ ?? 1QApplication @@ @ UAE XZ)在函數引用 」空隙__cdecl的GetValue(無效)「(的GetValue @@ YAXXZ)

guilib2.obj:錯誤LNK2019:解析外部符號」 __declspec(dllimport的)public:__thiscall QApplication :: QApplication(int &,char * *,int)「(_ imp? (void)__cdecl GetValue(void)「(?GetValue @@ YAXXZ)中引用的?0QApplication @@ QAE @ AAHPAPADH @ Z)

如何解決這個問題?

源下面的代碼:

guilib2.h

#ifndef GUILIB2_H 
    #define GUILIB2_H 

    #include "GUILib2_global.h" 

    GUILIB2SHARED_EXPORT void GetValue(); 

    #endif // GUILIB2_H 

GUILib2_Global.h

#ifndef GUILIB2_GLOBAL_H 
    #define GUILIB2_GLOBAL_H 

    #include <QtCore/qglobal.h> 

    #if defined(GUILIB2_LIBRARY) 
    # define GUILIB2SHARED_EXPORT Q_DECL_EXPORT 
    #else 
    # define GUILIB2SHARED_EXPORT Q_DECL_IMPORT 
    #endif 

    #endif // GUILIB2_GLOBAL_H 

guilib2.cpp

#include "guilib2.h" 
    #include <QtGui> 
    #include <QtWidgets/QApplication> 


    void GetValue() 
    { 
     int argc =1; 
     char *argv[1]; 
     argv[0]="guilib2.dll"; 
     QApplication a(argc,argv); 
    } 

GUILib2.pro

TARGET = GUILib2 
    TEMPLATE = lib 
    QT += gui 
    DEFINES += GUILIB2_LIBRARY 

    SOURCES += guilib2.cpp 

    HEADERS += guilib2.h\ 
      GUILib2_global.h 

回答

1

你應該在你的.pro文件中添加以下語句:

QT += widgets 
相關問題