Qt Plugin problem "Plugin verification data mismatch"



  • I am new to Qt and am trying to take advantage of the Qt plugin system. I am assuming that the plugin system is not just for developing Qt Creator/Designer plugins.

    My project design is package based in that it is designed to load individual "packages" that are modules and extensions of its interface. So I tried using the Qt plugin system to help accomplish this goal.

    Everything compiles fine. The problem is that I cannot load the plugin. It gives a "Plugin verification data mismatch" when I try too (that is the message is given with QPluginLoader::errorString).

    It may have something to do with using the macro: Q_EXPORT_PLUGIN2. I have seen this macro used in examples and the documentation for Qt says I should and I haven't yet done so. From what I have read however, this has something to do with using it in the Qt Designer. I do not need or want to export it to the Qt Designer (at least at this time). Is it still necessary?

    If it is, I cannot figure out how to use it. The documentation says that the arguments are the target name and the class name. Yet, when I put in the "target" name as specified by Visual Studio, it does not work. I get an error: C2338: Old plugin system used.

    If this is not the problem, then I cannot figure this out. I am using the same version of qt for all components of the project. I have used the Q_INTERFACES macro in the class derived from the interface (BuilderClient), and the Q_DECLARE_INTERFACE macro in the interface header.

    It might help to know that I am using the Visual Studio Qt plugin with Visual Studio 2010


  • Lifetime Qt Champion

    Hi,

    You should take a look at the Plug & Paint example. It shows how to create plugins for your application.

    Hope it helps



  • Ok. I followed the above advice and found one, possibly two (three?) problems. Fixing the first problem did not solve the issue. I am not sure what to do about the second problem because I use Visual Studio 2010.

    I was missing the Q_PLUGIN_METADATA macro. I put it in but I do not have a json "file" that specifies anything. According to the Q_PLUGIN_METADATA documentation, the FILE macro is optional. Is this not true? Do I need to make a json file? Putting in the Q_PLUGIN_METADATA macro did not solve my problem.

    The steps that are outlined in the example are:

    Declare a plugin class.

    Implement the interfaces provided by the plugin.

    Export the plugin using the Q_PLUGIN_METADATA() macro.

    Build the plugin using an adequate .pro file.

    One thing that might be important is that the plugin interface itself inherits from QObject and has the Q_OBJECT macro. This is different from the examples. Is this a problem? This seems my best approach because each object inherited from the same interface must give off the same set of signals and I cannot declare signals without using the Q_OBJECT macro. If this is a problem I will need away around this issue.

    Step 4 seems to be a problem because I am using Visual Studio. The instructions in the example were pretty explicit in what this file needs to include. How do I incorporate a .pro file when I am not using QtCreator as my IDE?



  • Folks, could someone please help me with this? I have been searching everywhere for a solution. I found out what I think is causing it but I still do not know how to get it to work.

    I am fairly certain that the problem is that I am using Visual Studio. The project .pro file requires that one adds the CONFIG += Plugin setting but there is no way to do this setting in visual studio that I am aware of.


  • Lifetime Qt Champion

    If you are not using the express edition, you have the Qt AddIn plugin for Visual Studio to handle Qt projects. Otherwise, you have to do it by hand. In that case, I recommend Qt Creator



  • I am using a professional version and the plugin. That was stated in my first post (at least the plugin part). However, I cannot find any setting for changing the config variable use in pro files for the qt project settings for the Visual Studio plugin. Is there a way to do that?



  • I believe I found a way to do the above. I added /D "QT_PLUGIN" to the C/C++ command line in the Visual Studio Project properties. I found that out by importing a .pro file with the CONFIG += Plugin set.

    However, that did not get rid of the error. I also put in a blank { } json file reference just to cover my bases as was done in the plug-n-paint example. No change.

    So I am going to post my code to see if anyone can find something wrong with the way I set everything up.

    First... the Interface class that is used (which is located in BuilderCore.dll):

    @
    #define BUILDER_ROLE_INTERFACE_IID "Builder.DefineRoleInterface/1.0"

    namespace BuilderCore
    {

    class BUILDERCORE_EXPORT IBuilderRole : public QObject, BuilderObject
    {
    Q_OBJECT

    public:
    IBuilderRole(const char* derivedRoleName, int roleID);
    virtual ~IBuilderRole();
    QList<IBuilderMode*>& GetModes() const;
    QList<QAction*>& GetActions() const;
    BuilderRoles GetRole() const;

    signals:
    void RoleAdded(); // triggered when Role has been initialized
    void RoleReady(); // triggered when Role is ready to begin
    void RoleStarted(); // triggered when Role has first started
    void RoleBeginRemove(); // triggered when Role needs to end
    void RoleEndRemove(); // triggered when Role has ended
    void RoleCleared(); // triggered just before dynamic library is unloaded

    public:
    virtual void AddRole() = 0;
    virtual void SetupRole() = 0;
    virtual void Start() = 0;
    virtual void Stop() = 0;
    virtual void ShutdownRole() = 0;
    virtual void RemoveRole() = 0;

    protected:
    QList<IBuilderMode*>& mModes;
    QList<QAction*>& mActions;
    BuilderRoles mRole;
    };

    }

    Q_DECLARE_INTERFACE(BuilderCore::IBuilderRole, BUILDER_ROLE_INTERFACE_IID)
    @

    Here is the header for the derived class that is the plugin. It is important to note that the plugin file contains several more classes other than this. Is that a problem? I

    NOTE: I had to comment out Q_OBJECT in order to get it to compile. I presume that is because this class inherits from QObject already (IBuilderRole is a QObject).

    @
    namespace BuilderCore
    {

    class BUILDERCLIENT_EXPORT BuilderClient : public IBuilderRole
    {
    //Q_OBJECT
    Q_PLUGIN_METADATA(IID BUILDER_ROLE_INTERFACE_IID FILE "builderclient.json")
    Q_INTERFACES(IBuilderRole)

    public:
    BuilderClient();
    ~BuilderClient();

    public:
    virtual void AddRole();
    virtual void SetupRole();
    virtual void Start();
    virtual void Stop();
    virtual void ShutdownRole();
    virtual void RemoveRole();

    private:
    //BuilderRoleData* roleData;
    };

    }
    @

    Finally... the relevant import code from the Builder.exe program

    @
    QPluginLoader loader(unpackDir.absoluteFilePath(folderfileName));
    loader.load();
    QString loaderError = loader.errorString();

    // QObject* object = loader.instance();
    // the following if statement is never true because loader.instance() is always null
    // the error is always the same.

    if (IBuilderRole* ifRole = qobject_cast<IBuilderRole*>(loader.instance()))
    {
    // inherited signal connections
    connect(ifRole, SIGNAL(RoleAdded()), this, SLOT(OnRoleAdded()));
    connect(ifRole, SIGNAL(RoleReady()), this, SLOT(OnRoleReady()));
    connect(ifRole, SIGNAL(RoleStarted()), this, SLOT(OnRoleStarted()));
    connect(ifRole, SIGNAL(RoleBeginRemove()), this, SLOT(OnRoleBeginRemove()));
    connect(ifRole, SIGNAL(RoleEndRemove()), this, SLOT(OnRoleEndRemove()));
    connect(ifRole, SIGNAL(RoleCleared()), this, SLOT(OnRoleCleared()));
    mRole = ifRole;

    //mRole->AddRole();
    }
    else
    failureString = new QString("Requested Role exists but the role could not be established.");
    @


  • Lifetime Qt Champion

    I wonder if it has something to do with the namespace… I haven't tried it with namespaced plugins.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.