1. ErrorString: failed to extract plugin meta data from this problem
Reason 1: The interface implementation class does not have Q_OBJECT
Reason 2: The Q_PLUGIN_METADATA statement was made, but the json file format is wrong
2. The problem of PluginLoader returns a QObject instance, but qobject_cast returns null (0x0) appears
Reason 1: The interface files are not uniform and the id of Q_DECLARE_INTERFACE is different
Interface file:
#ifndef APPINTERFACE_H
#define APPINTERFACE_H
#include <QtPlugin>
QT_BEGIN_NAMESPACE
class QWidget;
class QString;
class QObject;
QT_END_NAMESPACE
class AppInterface
{
public:
virtual ~AppInterface(){}
virtual QWidget *CreateWidget(QWidget *parent = nullptr)=0;
virtual QString name() = 0;
};
Q_DECLARE_INTERFACE(AppInterface, "id1233");
#endif // APPINTERFACE_H
Plug-in implementation class file:
#ifndef MYPLUGIN_H
#define MYPLUGIN_H
#include <QObject>
#include "appinterface.h"
class MyPlugin : public QObject, public AppInterface
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QGenericPluginFactoryInterface" FILE "plugin.json")
Q_INTERFACES(AppInterface)
public:
QWidget *CreateWidget(QWidget *parent);
QString name();
};
#endif // MYPLUGIN_H