Qt如何生成和使用DLL动态链接库

生成:

新建一个dll项目:

编译后会生成dll文件:

使用:

新建一个控制台项目:

把dll项目中的两个.h文件复制添加进来:

cpp 复制代码
QT -= gui

CONFIG += c++11 console
CONFIG -= app_bundle

DEFINES += QT_DEPRECATED_WARNINGS

SOURCES += \
        main.cpp
HEADERS += \
        scanfolder.h\
        scanfolder_global.h

LIBS+=E:\Qt\build-test-Desktop_Qt_5_12_9_MinGW_64_bit-Debug\debug\ScanFolder.dll


qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

然后把.dll文件复制到测试项目的编译文件中:

cpp 复制代码
#include <QCoreApplication>
#include "scanfolder.h"
#include "ScanFolder_global.h"
#include<iostream>
using namespace std;
int main()
{
    ScanFolder sf;
    cout<<sf.add(1,2);
}

成功~

相关推荐
blasit8 小时前
笔记:Qt C++建立子线程做一个socket TCP常连接通信
c++·qt·tcp/ip
郑州光合科技余经理5 天前
代码展示:PHP搭建海外版外卖系统源码解析
java·开发语言·前端·后端·系统架构·uni-app·php
feifeigo1235 天前
matlab画图工具
开发语言·matlab
dustcell.5 天前
haproxy七层代理
java·开发语言·前端
norlan_jame5 天前
C-PHY与D-PHY差异
c语言·开发语言
多恩Stone5 天前
【C++入门扫盲1】C++ 与 Python:类型、编译器/解释器与 CPU 的关系
开发语言·c++·人工智能·python·算法·3d·aigc
QQ4022054965 天前
Python+django+vue3预制菜半成品配菜平台
开发语言·python·django
遥遥江上月5 天前
Node.js + Stagehand + Python 部署
开发语言·python·node.js
m0_531237175 天前
C语言-数组练习进阶
c语言·开发语言·算法
Railshiqian5 天前
给android源码下的模拟器添加两个后排屏的修改
android·开发语言·javascript