QT development-dynamic link library creation

Reference video

One, create a dynamic link library project

Insert picture description here

2. Delete the global file and modify the code

#ifndef QTLIB_H
#define QTLIB_H

#include <QtGlobal>

// 导出类
class Q_DECL_EXPORT QtLib
{
    
    
public:

    QtLib();
};

//导出函数
extern "C" Q_DECL_EXPORT void LibFunc();
#endif // QTLIB_H

#include "qtlib.h"
#include<QDebug>

QtLib::QtLib()
{
    
    
   qDebug()<<"LibClass";

}


void LibFunc()
{
    
    
    qDebug()<<"LibFunc";
}

3. After compiling, find the following files and put them in the new project file directory

Insert picture description here

Fourth, ensure that the new project is not created in a shadow

Insert picture description here

Five, add code under the new project pro file

LIBS += -L. -lqtlib

Then you can call the functions in the library

#include <qtlib.h>
LibFunc();
QtLib lib;

Guess you like

Origin blog.csdn.net/peixin_huang/article/details/107352196