1.VS建立QT动态库
1)右键点击解决方案>>添加>>新建项目





!](https://img.haomeiwen.com/i12966642/56c0ca6f8bf7b1c9.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
7)动态库运行后,会生成X64\relese或X64\debug下面生成.dll和.lib文件。

2.测试生成的动态库
在mian 函数中包含"Dll.h"和"Dll.lib",直接在包含的适合写上路径,不用再属性中配置。再main函数中实例化一个Dll的对象,调用方法test(),并运行。
include "QtWidgetsApplication1.h"
include <QtWidgets/QApplication>
include "../Dll/Dll.h"
pragma comment(lib,"../x64/Debug/Dll.lib")
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Dll t;
t.test();
QtWidgetsApplication1 w;
w.show();
return a.exec();
}
运行成功,打印出test
网友评论