VC++生成DLL,Qt中使用DLL

一、        生成DLL

 

1.       新建DLL工程

生成DLL可以多种方法,这里介绍一种。在VS中,新建一个空的项目,选Win32 Console Application,新建完后修改工程属性:把生成EXE改为生成DLL

 

2.       源代码:

  

 

 

3.       编译连接,生成xyz.dll文件

 

二、使用DLL

 

1.     新建工程

 Qt Creator中创建一个新的GUI Application,在窗体上左边放置一个Label右边放置两个PushButton(Load和Quit)。

用Quit的Clicked()信号绑定close()槽,Load的Clicked()信号绑定Load()槽。

 

2.       源代码:

 

 

ps:Qt帮助文档中有这么一段说明

 

void * QLibrary::resolve(const char* symbol)

 

The symbol must be exported as a C function from the library. This means that the function must be wrapped in an extern "C" if the library is compiled with a C++ compiler. On Windows you must also explicitly export the function from the DLL using the_declspec(dllexport) compiler directive, for example:

 对于_declspec的说明参看 http://blog.csdn.net/lw02nju/archive/2009/07/22/4370002.aspx

 

 

 

 extern "C" MY_EXPORT int avg(int a, int b)
 {
     return (a + b) / 2;
 }

with MY_EXPORT defined as

 #ifdef Q_WS_WIN
 #define MY_EXPORT __declspec(dllexport)
 #else
 #define MY_EXPORT
 #endif

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值