1. 加载DLL

(1) pro种加载

LIBS+=$$PWD\XXX.dll

 

(2) QLibrary

QLibrary *libOCI = new QLibrary("F:\\oracle\\product\\10.2.0\\db_1\\bin\\oci.dll");
//加载动态库
libOCI->load();
if (!libOCI->isLoaded())
{
    printf("Load Oracle oci.dll failed!\n");
    return 0;
}

==>Qt生成的dll可以,但外部的dll不行

 

(3) addLibraryPath

QApplication::addLibraryPath("D:/Qt/Documents/build-FaceComparison-Desktop_Qt_5_9_8_MinGW_32bit-Release/release/");

 

(4) QPluginLoader

 void MainWindow::ReadPluginsInfo( const QString & pluginsDirPath /*= ""*/ )
{
    QString pluginsPath = pluginsDirPath;
    if (pluginsDirPath.isEmpty())
    {
        pluginsPath = QApplication::applicationDirPath();
    }
    QDir pluginsDir(pluginsPath);
    pluginsDir.cd("Plugins");

    QFileInfoList pluginsFile = pluginsDir.entryInfoList(QStringList() << "*.dll", QDir::Files);
    foreach(QFileInfo fileInfo, pluginsFile)
    {
        QPluginLoader loader(fileInfo.absoluteFilePath());
        bool isLoad = loader.isLoaded();
        QString info = loader.errorString();

        if (QObject * plugin = loader.instance())
        {
            qDebug() << isLoad;
        }
        else
        {
            qDebug() << loader.errorString();
        }
    }
}

 

 

 

 

QStringList paths = QCoreApplication::libraryPaths();


 


 

2. 加载lib

 

 

//运行目录获取

    QString applicationDirPathStr = QApplication::applicationDirPath();
    qDebug() << "----------运行目录获取-------------"<<applicationDirPathStr;

    //运行环境目录获取
    QString applicationDirPathStr2 = QDir::currentPath();
    qDebug() << "----------运行环境目录获取-------------"<<applicationDirPathStr2;


 

posted on 2020-05-18 18:16  刘达人186  阅读(4176)  评论(0编辑  收藏  举报