Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Problem with Qt low-level dynamic plugins: The specified module could not be foundd



  • Hello community,

    I have a program which loads .dll plugins at runtime similar to the "Echo Plugin" example in the Qt docs (https://doc.qt.io/qt-5/qtwidgets-tools-echoplugin-example.html). This has worked previously, but for some reason (it is possible that I made changes which broke the loader), it stopped working and now I am unable to load any plugins.

    Let me show you my interface first which is a part of my main application / main window:

    #ifndef PLUGININTERFACE_H
    #define PLUGININTERFACE_H
    
    #include <QtPlugin>
    
    // forward declarations
    class MainWindow;
    struct P3DData;
    
    class PluginInterface
    {
    public:
        //virtual ~PluginInterface() = 0;
        virtual bool createPublisher(MainWindow*, P3DData*) = 0;
    };
    
    #define PLUGIN_INTERFACE_iid "PluginInterface"
    Q_DECLARE_INTERFACE(PluginInterface, PLUGIN_INTERFACE_iid)
    
    #endif // PLUGININTERFACE_H
    

    I then load all plugins within the "/plugins" directory using the following method within my MainWindow class:

    bool MainWindow::loadPlugins()
    {
        QDir pluginsDir(qApp->applicationDirPath());
        pluginsDir.cd("plugins");
    
        const auto entryList = pluginsDir.entryList(QDir::Files);
        for(const QString &fileName : entryList)
        {
            QString dllPath = pluginsDir.absoluteFilePath(fileName);
    
            if(!fileName.contains(".dll")) continue;
    
            QPluginLoader* loader = new QPluginLoader(dllPath);
            loaderList.push_back(loader);     
            QObject *plugin = loader->instance();
    
            if (plugin)
            {
                qDebug() << "[PluginLoader] Lade" << fileName;
    
                pluginList.push_back(qobject_cast<PluginInterface *>(plugin));
                pluginList.last()->createPublisher(this, simDataPtr);
                pluginCount++;
    
                pushToLogBox("[PluginLoader] " + fileName + " wurde erfolgreich geladen!");
                continue;
            }
            else
            {
                pushToLogBox("[PluginLoader] Fehler: '" + fileName + "': " + loader->errorString());
                delete loaderList.takeLast(); // takeLast() entfernt im  auch automatisch den Eintrag im Vektor (im Gegensatz zu last())!
            }
        }
    
        updateUI();
    
        if(pluginCount > 0)
        {
            pushToLogBox(QString("[PluginLoader] Es wurden ") + QString(std::to_string(pluginCount).c_str()) + QString(" Plugin(s) geladen!"));
            return true;
        }
    
        pushToLogBox("[PluginLoader] Es konnte kein Plugin geladen werden!");
        return false;
    }
    

    The header of the main class of my plugin looks like that:

    #ifndef _POSITION_PUBLISHER_H_
    #define _POSITION_PUBLISHER_H_
    
    #include <QObject>
    #include <thread>
    
    #include <fastrtps/fastrtps_fwd.h>
    #include <fastrtps/publisher/PublisherListener.h>
    
    #include "PositionPubSubTypes.h"
    #include "MainWindow.h"
    
    using namespace eprosima::fastrtps;
    
    
    class PositionPublisher : public QObject, PluginInterface
    {
        Q_OBJECT
        Q_PLUGIN_METADATA(IID "PluginInterface")
        Q_INTERFACES(PluginInterface)
    
    public:
        PositionPublisher();
        ~PositionPublisher();
        bool createPublisher(MainWindow* _window, P3DData* _simDataPtr) override;
        // ....
    };
    
    #endif // _POSITION_PUBLISHER_H_
    

    In the .pro file of the plugin I also define "CONFIG += plugin".

    Now the problem when running the loadPlugins() method is, that it checks the correct Position.dll file, but loader->instance() returns null and the loader->errorString() looks as follows:

    Cannot load library F:\DEV\build\simNET\bin\plugins\Position.dll: The specified module could not be found

    As far as I can tell, my code matches pretty exactly the one from the Echo Plugin example, with the difference that my loadPlugins method is capable to load multiple plugins. What is the problem here?

    Thank you all very much.



  • push: I still have that problem


  • Lifetime Qt Champion

    Make sure that all Dependencies of Position.dll is in your PATH



  • I tried adding the following paths to my PATH env variable:

    The libraries the plugin depends on (path correct, I am also including these in my main application and that works fine)

    F:\Programme\Prepar3D v4\SDK\inc\SimConnect
    F:\Programme\Prepar3D v4\SDK\lib\SimConnect
    
    F:\DEV\prog\FastRTPSv1.5\include
    F:\DEV\prog\FastRTPSv1.5\lib\x64Win64VS2015
    

    The plugin folder, where the actual plugin is deployed to after compilation. The main application is in the bin folder

    F:\DEV\build\simNET\bin\plugins
    

    Still the same error...

    EDIT: Is it possible that something with my Qt installation is wrong or is that issue not connected to that?

    EDIT2: Btw I also tried to place the plugins in the bin folder, so in the same directory where my main application .exe is located, then changed the loadPlugins() method a little, so that it looks in the bin directory and the result is still the same again...


  • Lifetime Qt Champion

    Hi,

    You should start your application with the QT_DEBUG_PLUGINS environment variable set to 1. It should show more information with regard to plugin loading.


Log in to reply