加载qt5项目的插件时“插件验证数据不匹配”

时间:2022-06-14 23:16:45

I have raw (no QtDesigner) Qt5 project with two simple plugins, which one don't load with laconic error: "plugin verification data mismatch".

我有两个简单插件的原始(没有QtDesigner)Qt5项目,其中一个没有加载简洁错误:“插件验证数据不匹配”。

Header of first plugin (which loads and run well):

第一个插件的标题(加载并运行良好):

#ifndef __PIROGRONIAN__P2P2__GUI_PLUGIN__H__
#define __PIROGRONIAN__P2P2__GUI_PLUGIN__H__

#include "QtCore/QtCore"
#include "PluginInterface.h"

namespace P2P2 {

    class GuiPlugin : public QObject, public PluginInterface {
        Q_OBJECT
        Q_PLUGIN_METADATA(IID "Pirogronian.P2P2.GuiPlugin")
        Q_INTERFACES(P2P2::PluginInterface)

    public:
        bool init(CoreServer *);
        bool receiveObject(Object*);
        int channelType();
    };
};

#endif

The second one, which don't load:

第二个,不加载:

#ifndef __PIROGRONIAN__P2P2__CHAT_PLUGIN__H__
#define __PIROGRONIAN__P2P2__CHAT_PLUGIN__H__

#include <QtNetwork/QtNetwork>
#include "Chat.h"
#include "PluginInterface.h"

namespace P2P2 {

    class ChatPlugin : public QObject, public PluginInterface {
        Q_OBJECT
        Q_PLUGIN_METADATA(IID "Pirogronian.P2P2.ChatPlugin")
        Q_INTERFACES(P2P2::PluginInterface)

        CoreServer *_server;
        QHash<Channel *, Chat *> _chats;

    public:
        virtual bool init(CoreServer *);
        virtual bool receiveObject(Object *);
        virtual int channelType();
    };

};

//Q_DECLARE_METATYPE(QPointer<P2P2::ChatPlugin>)

#endif

Here is PluginInterface header:

这是PluginInterface头:

#ifndef __PIROGRONIAN__P2P2__PLUGIN_INTERFACE__H__
#define __PIROGRONIAN__P2P2__PLUGIN_INTERFACE__H__

#include "CoreServer.h"

namespace P2P2 {

    class PluginInterface {
    public:
        virtual bool init(CoreServer *) = 0;
        virtual bool receiveObject(Object *) = 0;
        virtual int channelType() = 0;
    };

};

Q_DECLARE_INTERFACE(P2P2::PluginInterface, "Pirogronian/P2P2/PluginInterface/1.0")

#endif

I'm not expert and writing plugins for qt5 is described very cursorily. But since I can't find any major difference between those plugins, problem becomes rather mysterious to me. Mayby a bug in Qt? I've rebuilt both several times to bye sure that both are up to date.

我不是专家,为qt5编写插件的描述非常轻松。但是由于我找不到这些插件之间的任何重大差异,问题对我来说变得相当神秘。 Mayby在Qt的一个错误?我已经多次重建,以确保两者都是最新的。

I'm trying put the whole code somewhere into net, but it'll take a while... Edit: done - packed as zip here: http://uploaduj.net/D74c2f/v0-1-pure-zip/

我正在尝试把整个代码放到网上,但它需要一段时间...编辑:完成 - 打包为zip:http://uploaduj.net/D74c2f/v0-1-pure-zip/

1 个解决方案

#1


Not sure if it helps but it seems that your plugin has invalid metadata. Here's code that sets error message http://code.qt.io/cgit/qt/qtbase.git/tree/src/corelib/plugin/qlibrary.cpp#n303

不确定它是否有帮助,但似乎您的插件具有无效的元数据。这是设置错误消息的代码http://code.qt.io/cgit/qt/qtbase.git/tree/src/corelib/plugin/qlibrary.cpp#n303

You could use debug version of Qt and set breakpoint in that function. This would give you exact line that fails while loading your plugin.

您可以使用Qt的调试版本并在该函数中设置断点。这将为您提供加载插件时失败的确切行。

Maybe you have an error in your metadata?

也许您的元数据中有错误?

#1


Not sure if it helps but it seems that your plugin has invalid metadata. Here's code that sets error message http://code.qt.io/cgit/qt/qtbase.git/tree/src/corelib/plugin/qlibrary.cpp#n303

不确定它是否有帮助,但似乎您的插件具有无效的元数据。这是设置错误消息的代码http://code.qt.io/cgit/qt/qtbase.git/tree/src/corelib/plugin/qlibrary.cpp#n303

You could use debug version of Qt and set breakpoint in that function. This would give you exact line that fails while loading your plugin.

您可以使用Qt的调试版本并在该函数中设置断点。这将为您提供加载插件时失败的确切行。

Maybe you have an error in your metadata?

也许您的元数据中有错误?