0
votes

I need to create dinamic library based on Qt with some function, for example GetValue. This function should call dialog with QLineEdit and return input value. I created structure without Qt classes. Source code is compiled succesfully and I got dll.

But when I add Qt objects I get linkage error like this:

guilib2.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual _thiscall QApplication::~QApplication(void)" (_imp_??1QApplication@@UAE@XZ) referenced in function "void __cdecl GetValue(void)" (?GetValue@@YAXXZ)

guilib2.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall QApplication::QApplication(int &,char * *,int)" (_imp??0QApplication@@QAE@AAHPAPADH@Z) referenced in function "void __cdecl GetValue(void)" (?GetValue@@YAXXZ)

How to solve this problem?

Source code below:

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

1 Answers

1
votes

You should add this statement in your .pro file:

QT += widgets