首页 > 编程语言 > 详细

C++接口库调用方法(QT)

时间:2021-01-19 12:36:34      阅读:103      评论:0      收藏:0      [点我收藏+]
#ifndef ICONNECT_H
#define ICONNECT_H
#include <QtCore/qglobal.h>
#if defined(MYDLL_LIBRARY)
#  define MYDLL_EXPORT Q_DECL_EXPORT
#else
#  define MYDLL_EXPORT Q_DECL_IMPORT
#endif
 
///接口类
class IConnect
{
public:
    virtual ~IConnect(){}
    //static IConnect* createEx();
    virtual int sum(int a, int b) = 0;
    virtual int sub(int a, int b) = 0;
};

extern "C" MYDLL_EXPORT IConnect* Create();
 
#endif //ICONNECT_H
 
#include "../Interface/IConnect.h"
 
//MyDll继承接口类IConnect
class MyDll : public IConnect
{
public:
    MyDll();
    int sum(int a, int b) override;
    int sub(int a, int b) override;
};
 
//实现类
#include "mydll.h"
 
MyDll::MyDll()
{
}
int MyDll::sum(int a, int b)
{
    return  a + b;
}
int MyDll::sub(int a, int b)
{
    return  a - b;
}
///注意
extern "C" MYDLL_EXPORT IConnect* Create()
{
    return new MyDll();
}
 
///将MyDll的lib和dll文件加载库后 调用
IConnect* connect = Create();
cout<<connect->sum(3, 5)<<endl;
 
可以继续封装
技术分享图片
 
技术分享图片
 
技术分享图片
 
 
 

C++接口库调用方法(QT)

原文:https://www.cnblogs.com/kinglxg/p/14296642.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!