[SOLVED] QPluginLoader unable to load a Qt Plugin

  • Hello all,

    I have an Interface as shown below.

    class MyInterface
            virtual ~MyInterface() {}
            virtual int initialize() = 0;
    Q_DECLARE_INTERFACE(MyInterface, "com.example.MyInterface/1.0")

    My plugin implements this interface and declares it in its class as shown below.

    class QT_DECL_EXPORT MyPlugin : public QObject, public MyInterface
            virtual ~MyPlugin();
            int initialize();
            // ...

    My plugin's project file sets the target appropriately.

    TARGET = $$qtLibraryTarget(MyPlugin)
    TEMPLATE = lib

    Now, all the modules (including my app) gets compiled. In the app where I have to load the plugin, I have the following code:

    // ...
    QPluginLoader loader("MyPluginld.dll");
    if (! loader.load())
        qDebug() << "Error!";
    MyInterface *base = qobject_cast<MyInterface *>(loader.instance());
    if (base == NULL)
        qDebug() << "Error!";
    // ...

    The loader.load() function always fails. Am I making a mistake by providing incorrect name to the QPluginLoader constructor? Or is something else wrong?

    Any help would be much appreciated.


  • In your code you expect that the DLL is in the same directory of the executable.
    Is that TRUE??

  • @mcosta Yes, that is correct. My deployment model ensures that both land up in the same directory.

    ಮೈ ಗೋ ಭರತ ನಾರಾಯಣ
    Bharath Narayan M G

  • Hi,

    if your DLL is in the right place you can use QPluginLoader::errorString()to understand why load fails

  • @mcosta Thanks for that. I will see what the error string says.

  • @mcosta
    The errorString prints the following:

    "Plugin verification data mismatch in './/MyPluginld.dll'"

  • @bharath144 said:

    Plugin verification data mismatch in

    Had a quick look to Qt sources.
    Seems that you must use this macro to define plugin's metadata.

    Reading here, the point 3. of "Writing a plugin involves these steps:" says the same thing

  • @mcosta That did the trick. I saw the step but I overlooked it thinking it may not be mandatory.

    Thanks for the help.

  • hello,

    can you tell us how you solve your problem?
    thank you.