Qt dll的导出与调用
2013-09-13 13:10
363 查看
Qt中动态链接库(dll)的导出
testdll_global.h
testdll.h
testdll.cpp
编译后生成 lib文件和dll文件
dll文件的隐式调用
1 需要在调用程序中引入 testdll.h文件
2 需要导入testdll.lib文件 #pragma comment(lib, "testdll.lib")
testdll_global.h
#ifndef TESTDLL_GLOBAL_H #define TESTDLL_GLOBAL_H #include <QtCore/qglobal.h> #if defined(TESTDLL_LIBRARY) # define TESTDLLSHARED_EXPORT Q_DECL_EXPORT #else # define TESTDLLSHARED_EXPORT Q_DECL_IMPORT #endif #endif // TESTDLL_GLOBAL_H
testdll.h
#ifndef TESTDLL_H
#define TESTDLL_H
#include <QDebug>
#include "testdll_global.h"
class TESTDLLSHARED_EXPORT Testdll
{
public:
Testdll();
public:
static void add( int a1, int a2 );
static void sub( int s1, int s2 );
};
extern "c" TESTDLLSHARED_EXPORT void mul( int m1, int m2 );
#endif // TESTDLL_H
testdll.cpp
#include "testdll.h" Testdll::Testdll() { } void Testdll::add(int a1, int a2) { qDebug()<<"a1+a2="<<a1+a2; } void Testdll::sub(int s1, int s2) { qDebug()<<"s1-s2="<<s1-s2; } void mul(int m1, int m2) { qDebug()<<"m1*m2="<<m1*m2; }
编译后生成 lib文件和dll文件
dll文件的隐式调用
1 需要在调用程序中引入 testdll.h文件
2 需要导入testdll.lib文件 #pragma comment(lib, "testdll.lib")
#include <QCoreApplication> #include "./lib/testdll_global.h" #include "./lib/testdll.h" #include <QLibrary> #pragma comment(lib, "./lib/testdll.lib") TESTDLLSHARED_EXPORT void mul( int, int); int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); Testdll::add( 3, 5 ); Testdll::sub( 5, 2 ); mul( 2, 7); return a.exec(); }
相关文章推荐
- QT导出dll 与 QT调用dll
- C#中调用C++的dll的参数为指针类型的导出函数(包括二级指针的情况)
- DLL 导出 导入 调用约定
- vs下opencv的人脸检测以及qt下dll的封装调用(一、opencv下的人脸检测以及图片的保存)
- DLL 导出函数 _stdcall 和 _cdecl调用约定
- qt 调用dll
- 在ObjectArx中调用dll中的导出对话框或控件时的注意事项
- Qt调用dll中的功能函数
- DLL导出函数的声明和调用
- 调用未知DLL中的导出函数[转]
- VB调用DLL导出函数出现“Bad DLL call convention”的解决
- QT生成DLL并调用DLL
- mfc调用qt的dll
- Qt5.9动态调用c++的dll方法(Qt5.9调用MQTT的一个实例)
- [转] 调用未知DLL中的导出函数
- QT 生成DLL并显示调用
- Qt 编写DLL 并调用
- Qt中隐式调用VS建立的dll动态库
- QT中DLL的生成和调用(查了些资料在同事的帮助下完成)
- 创建及调用QT的DLL