logplus/OSGDataModel/src/ObjectGenralFactory.cpp
2025-10-29 17:23:30 +08:00

52 lines
1.4 KiB
C++

#pragma warning( push ,0)
#include <map>
#include <QStringList>
#include <QCoreApplication>
#include <QDir>
#include <QLibrary>
#include "ObjectGenralFactory.h"
// #include "error.h"
#include <QMessageBox>
#pragma warning( pop )
BEGIN_OSGDATAMODEL_NAMESPACE;
OSGDATAMODEL_EXPORT QStringList LoadAllPlugin(const QString &PluginTypeName)
{
QStringList dllnames;
//加载插件的目录
QStringList listFolder;
{
QString strPathTmp = QCoreApplication::applicationDirPath() + QDir::separator();
//listFolder << strPathTmp;
listFolder << strPathTmp+ PluginTypeName+ QDir::separator();
}
//遍历加载所有的plugin 插件
for( long iFolder = 0 ; iFolder < listFolder.size();++iFolder )
{
QDir dir(listFolder[iFolder] );
QFileInfoList listDllFile = dir.entryInfoList(QDir::Files | QDir::NoDotAndDotDot);
std::string errormsg="";
for (int j = 0; j < listDllFile.size(); ++j)
{
QString strDllPath = listDllFile[j].filePath();
//加载插件
QLibrary Library( strDllPath );
if(Library.isLibrary(strDllPath)){
bool bLoaded = Library.load();
if(!bLoaded)
errormsg="加载插件出错:["+PluginTypeName.toStdString()+"]"+strDllPath.toStdString()+"错误原因:"+Library.errorString().toStdString()+"\n";
else dllnames.append(strDllPath);
}
}
if(errormsg!="") {
QMessageBox::warning(NULL,"提示",errormsg.c_str());
}
}
return dllnames;
}
END_OSGDATAMODEL_NAMESPACE