Today with the QT compilation generated by the shared library itself but how can not call, check the n long to find this post, found out, record a
Http://qiusuoge.com/12720.html
How does Qt invoke VC + + generated dynamic link library? Assume that there are currently VC + + compiler generated dynamic library files Testdll.h,testdll.lib and Testdll.dll.
Testdll.h File source code is as follows:
#ifdef Testdll_exports
#define TESTDLL_API __declspec (dllexport)
#else
#define TESTDLL_API __declspec (dllimport)
#endif
This class is derived from Testdll.dll.
Class Testdll_api Ctestdll {
Public
Ctestdll (void);
Public
int Add (int a, int b) {return a+b;}
int Sub (int a, int b) {return a-A;}
int Mul (int a, int b) {return a*b;}
};
extern Testdll_api int ntestdll;
Testdll_api int fntestdll (void);
How does qt use these dynamic link library files?
One, Situation 1, programming environment is Qt CREATOR+QT libraries 4.8.6 for Windows (VS 2010)
QT Library is VS2010 version, VC + + compiler generated. So the project can directly use the Testdll.h header file and the Testdll.lib to lead the library file.
1, copy the testdll.h to the project path;
2, the project document Xxx.pro need to manually add "HEADERS + = testdll.h" and "LIBS + + testdll.lib";
3. Before compiling, you need to copy the Lib file: Testdll.lib and Testdll.dll together under the build path.
In this way, VC + + dynamic link library functions can be used normally.
Ii. Scenario 2, the programming environment is Qt CREATOR+QT libraries 4.8.6 for Windows (MinGW 4.8.2)
QT Library is a mingw version, the GCC compiler generated, and VC + + compiler is not the same system. So the project can not use Testdll.h header file and testdll.lib to lead the library file.
For the method that invokes the DLL, QT itself has a corresponding class to implement.
#include "Dialog.h"
#include <QApplication>
#include <QLibrary>
typedef int (*FUNC_ADD) (int a, int b); Defining function pointers
typedef int (*FUNC_SUB) (int a, int b);
typedef int (*FUNC_MUL) (int a, int b);
int main (int argc, char *argv[])
{
Qapplication A (argc, argv);
Qlibrary mylib ("Testdll.dll");//testdll.dll's storage path is consistent with the. exe
if (Mylib.load ())
{
"[Email Protected]@@[email protected]" string is actually a variant of the dynamic library function int Add (int a, int b), please use Microsoft tools DEPENDS.EXE to see
Func_add f1 = (func_add) mylib.resolve ("[Email protected]@@[email protected]");
Func_sub F2 = (func_sub) mylib.resolve ("[Email protected]@@[email protected]");
Func_mul F3 = (Func_mul) mylib.resolve ("[Email protected]@@[email protected]");
int rt = 0;
if (f1! = NULL)
{
RT = F1 (10, 12);
}
if (F2! = NULL)
{
RT = F2 (10, 12);
}
if (F3! = NULL)
{
RT = F3 (10, 12);
}
}
Dialog W;
W.show ();
return A.exec ();
}
qt different version compiler, call VC + + generated dynamic link library