One, create a dynamic link library project
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
Fourth, ensure that the new project is not created in a shadow
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;