2

I use Qt 5.3 and when calling

QPluginLoader pluginLoader(pluginsDir.absoluteFilePath(fileName));
bool pluginLoaded = pluginLoader.isLoaded();

It gives false :(

// serverplugin.h

    #ifndef SERVERPLUGIN_H
#define SERVERPLUGIN_H

#include <QObject>
#include <QtPlugin>
#include "acepos/aceclient/serverinterface.h"

#include <QThread>
#include "server.h"

class ServerPlugin : public QObject,
                     public ServerInterface
{
    Q_OBJECT
    Q_PLUGIN_METADATA(IID "org.qt-project.Qt.AcePos.ServerInterface/1.1" FILE "serverplugin.json")
    Q_INTERFACES(ServerInterface)
    QThread *m_pServerThread;
    Server *m_pServer;

public:
    ServerPlugin():m_pServerThread(NULL), m_pServer(NULL){}

private slots:
    //void handleServiceStartNotify();

public:
    bool startServerService();
    bool stopServerService();
};

#endif

// serverinterface.h

#ifndef SERVERINTERFACE_H
#define SERVERINTERFACE_H

#include <QtPlugin>

class ServerInterface
{
public:
    virtual ~ServerInterface() { }
    virtual bool startServerService() = 0;
    virtual bool stopServerService() = 0;
};

#define ServerInterface_iid "org.qt-project.Qt.AcePos.ServerInterface/1.1"

Q_DECLARE_INTERFACE(ServerInterface, ServerInterface_iid)

#endif // SERVERINTERFACE_H

Please let me know if anything wrong im doing in creating plugin.

When I build the plugin project I am able to see the generated library file. I am doing this for android qt project. When debugging it works fine. I had made changes in the plugin part during development.

A.J
  • 725
  • 10
  • 33
  • What das errorString() say? – Silicomancer Oct 11 '14 at 07:44
  • errorString says :"Plugin verification data mismatch" – A.J Oct 11 '14 at 08:03
  • In windows machine even if pluginloader says false, i am able to get plugin instance QObject *plugin = pluginLoader.instance(); if (plugin) { qDebug()<(plugin); if (NULL != m_pServerInterface) { qDebug() << Q_FUNC_INFO << "plugin loaded successfully"; } even – A.J Oct 11 '14 at 08:04
  • Are you sure that in release mode you're loading release build of plugin? QPluginLoader won't load debug plugins in release mode and vice versa – Kamil Klimek Oct 11 '14 at 08:52
  • sorry this error occurs when it tries to load .a file but when it tries to load .dll `void MainFrame::loadPlugin() fileName "serverplugind.dll" void MainFrame::loadPlugin() pluginLoaded false void MainFrame::loadPlugin() pluginLoaded "Unknown error"` – A.J Oct 11 '14 at 09:34
  • You cannot load an `.a` file as a plugin. `.a` files are **static** libraries that can only be linked at compile-time. – dom0 Oct 11 '14 at 09:46

2 Answers2

3

QPluginLoader makes the following checks:

  • Same build configuration (release/debug, except on Unix-like systems)
  • Same major version and minor/patch version equal or smaller than application minor/patch version of Qt

When developing one sometimes forgets to rebuild a plugin with the correct Qt configuration, leading to the plugin not loaded. Solution: rebuild plugin with the correct build configuration.

You can also set QT_DEBUG_PLUGINS=1 in the launch environment of the application to get more verbose debugging information about plugin loading.

dom0
  • 7,356
  • 3
  • 28
  • 50
1

I stumbled upon this problem yesterday and here is what I did to fix it: Please note that both my plugin and the app that was consuming the plugin were in debug mode and built with the same version of Qt, so that was not the problem. The problem was that I had forgotten to put the following line in the main export class of the plugin:

Q_PLUGIN_METADATA(IID "namespace.if.any.classname" FILE "package.json")

After this I had no problem loading the plugin.

santahopar
  • 2,933
  • 2
  • 29
  • 50
  • @Abin, I know that you do. I just decided to post this answer in case if someone will face the same problem not due to the same reasons as you. – santahopar Mar 18 '16 at 17:06