定义的接口
----------------------------------------------
#ifndef REGEXPINTERFACE_H
#define REGEXPINTERFACE_H
#include <QString>
class RegExpInterface
{
public:
    virtual ~RegExpInterface()
    {

    }
    virtual QString regexp(const QString &message)=0;
};
Q_DECLARE_INTERFACE(RegExpInterface, "org.myplugin.RegExpInterface")
#endif // REGEXPINTERFACE_H

实现的接口的类 头文件
---------------------------------------------
#define REGEXPPLUGIN_H
#include <QObject>
#include <QString>
#include "regexpinterface.h"

class RegExpPlugin : public QObject, RegExpInterface
{
    Q_OBJECT
    Q_PLUGIN_METADATA (IID "org.myplugin.RegExpInterface")
    Q_INTERFACES(RegExpInterface)

public:
    QString regexp(const QString &message);

};

#endif // REGEXPPLUGIN_H

源文件
-------------------------------------
#include "regexpplugin.h"
QString RegExpPlugin::regexp(const QString &message)
{
    return "hello world";
}



pro 文件
-------------------------------------
HEADERS += \
    regexpplugin.h \
    regexpinterface.h
SOURCES += \
    regexpplugin.cpp
TEMPLATE=lib
CONFIG  +=plugin
TARGET =regexpplugin

测试插件的窗口

窗口的头文件
-----------------------------------------
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include "regexpinterface.h"
#include <QPluginLoader>



namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

private slots:
    void on_pushButton_clicked();

private:
    RegExpInterface *regInterface;
    Ui::MainWindow *ui;
    bool loadPlugin();
};

#endif // MAINWINDOW_H

窗口的源文件
----------------------------------------
#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}

bool MainWindow::loadPlugin()
{
      QPluginLoader loader("../plug/plugin.dll");
        QObject *obj= loader.instance();
        if(obj)
        {
            regInterface=qobject_cast<RegExpInterface *>(obj);

            if(regInterface)
            {
               QString str= regInterface->regexp("jjjkk");
               ui->Result->setText(str);
            }

        }

}

void MainWindow::on_pushButton_clicked()
{
    this->loadPlugin();
}



插件中常用的pri文件
------------------------------------------------
HEADERS += \
    $$PWD/common/HpQRCodeInterface.h

PROJECT_COMPONENTSOURCE = $$PWD/common
PLUGIN_INSTALL_DIRS = $$[QT_INSTALL_LIBS]/ukui-demo-plugin









最新文章

  1. winform中button点击后再点击其他控件致使button失去焦点,此时button出现黑色边线,去掉黑色边线的方法
  2. ACID
  3. Support Vector Machine (1) : 简单SVM原理
  4. itoa
  5. Linux 套接字编程中的 5 个隐患
  6. Docker学习笔记(4) — 开启Docker远程访问
  7. malloc内存分配与free内存释放的原理
  8. HDU 1890 Robotic Sort | Splay
  9. 整理JRE瘦身或精简JRE
  10. Java 计算两个日期相差月数、天数
  11. Git(介绍和安装)
  12. Cygwin命令
  13. GooglePlay发布应用后,支持的 Android 设备 0 台设备
  14. 【Codeforces 332C】Students&#39; Revenge
  15. linux下比较两个文本文件的不同——diff命令
  16. httppost core net
  17. POJ 1743 Musical Theme (字符串HASH+二分)
  18. 2018-2019-1 1723《程序设计与数据结构》第1&amp;2周作业 总结
  19. Codeforces Round #417 (Div. 2) B. Sagheer, the Hausmeister
  20. Google Voice号码使用说明及用途

热门文章

  1. File类与常用IO流第七章——Properties集合
  2. HDFS学习总结之API交互
  3. Echarts入门踩坑记录
  4. Python高阶之多线程锁机制
  5. PAT乙级:1077 互评成绩计算 (20分)
  6. 离散数学-传递闭包(POJ3275)
  7. 第五篇--Chorme浏览器主页被篡改
  8. videojs文档翻译-SeekBar
  9. Couchdb 任意命令执行漏洞(CVE-2017-12636)
  10. SpringCloud升级之路2020.0.x版-4.maven依赖回顾以及项目框架结构