QT插件系统

  1. 创建接口头文件,Q_DECLARE_INTERFACE,定义接口

    #ifndef PLUGINONEINTERFACE_H
    #define PLUGINONEINTERFACE_H
    #include
    // 组织域名+产品名+版本号
    #define PluginOneInterfaceIID "baidu.com.PluginOneInterface/1.0"
    class PluginOneInterface
    {
    public:
    virtual ~PluginOneInterface() = default;
    virtual QWidget* getWidget() = 0;
    };
    Q_DECLARE_INTERFACE(PluginOneInterface,PluginOneInterfaceIID)
    #endif // PLUGINONEINTERFACE_H

  2. 编写插件类,继承接口类

    class PLUGINONE_EXPORT PluginOne:public QObject ,public PluginOneInterface
    {
    Q_OBJECT
    Q_PLUGIN_METADATA(IID PluginOneInterfaceIID FILE "PluginOne.json")
    Q_INTERFACES(PluginOneInterface)
    public:
    PluginOne();
    ~PluginOne();
    QWidget * getWidget() override;
    private:
    QWidget * mWidget{nullptr};
    };

  3. 主项目加载插件

  4. 获取插件中元数据Q_PLUGIN_METADATA的json数据

    QJsonObject meta = loader.metaData();
    QJsonObject metaData = meta.value("MetaData").toObject();
    QString version = metaData.value("version").toString();
    QString name = metaData.value("name").toString();

相关推荐
xcyxiner12 小时前
DicomViewer (后台线程处理文件)4
qt
xcyxiner19 小时前
DicomViewer (添加模型类)3
qt
xcyxiner2 天前
DicomViewer (目录调整) 2
qt
xcyxiner2 天前
dcmtk vtk vtk-dicom(gdcm) 编译(debug) v2
qt
桥田智能4 天前
桥田智能 QT-650S:面向白车身焊装的 800kg 重载快换解决方案
开发语言·qt·系统架构
森G4 天前
75、服务器源码解析---------云视频服务项目
linux·服务器·网络·c++·qt
森G4 天前
77、线程池原理和实现------服务器源码解析----云视频服务项目
服务器·c++·qt
森G4 天前
71、打包发布---------打包发布
c++·qt
初圣魔门首席弟子4 天前
Node.js 详细介绍(知识库版)
windows·qt·node.js·知识库
C++ 老炮儿的技术栈4 天前
Qt工控实战:自研机器人TCP长连接客户端(粘包处理+心跳保活+自动重连完整源码解析)
qt·tcp/ip·机器人