QT CTK插件开发(六) 多对一插件

news2024/12/25 2:02:24

        CTK在软件的开发过程中可以很好的降低复杂性、使用 CTK Plugin Framework 提供统一的框架来进行开发增加了复用性 将同一功能打包可以提供多个应用程序使用避免重复性工作、可以进行版本控制提供了良好的版本更新迭代需求、并且支持动态热拔插 动态更新、开发更加简单快捷 方便有用的开发,方便公司的持续技术积累和代码、模块、功能的统一管理和持续更新完成,对于企业实际开发过程中有比较重要的意义。

        本专栏文章较为全面的讲述了CTK插件开发的全部步骤,包括不限于 CTKPlugin插件、服务-接口(一服务对一接口)、服务-接口(多服务对一接口)、服务-接口(多接口对一服务)、CTK插件批量加载、CTK插件热拔插、CTK事件监听、CTK事件发送-类通信、CTK事件发送-信号槽、CTK版本控制、CTK版本控制、CTK插件元数据、CTK 服务工厂、CTK 服务追踪、控制中心软件开发CTK 等文章;

        CTK Plugin Framework基于Qt Plugin System和Qt Service Framework实现,并且增加了以下特性来扩展:插件元数据(由MANIFEST.MF文件提供)、一个定义良好的插件生命周期和上下文、综合服务发现和注册;

        Plugin System:CTK Core依赖于QtCore模块,CTK Plugin Framework基于Qt Plugin System。Qt API允许在运行时加载和卸载插件,热插拔功能在CTK Plugin Framework中得到了加强,以支持透明化延迟加载和解决依赖关系。

        插件的元数据被编译进插件内部,可以通过API进行提取。此外,插件系统还使用SQLite缓存了元数据,以避免应用程序加载时间问题。另外,Plugin System支持通过中央注册中心使用服务。

        Service Registry:Qt Service Framework是Qt Mobility项目发布的一个Qt 解决方案,Qt服务框架允许“声明式服务”和按需加载服务实现。为了启用动态(非持久性)服务,Qt Mobility服务框架可以与Service Registry一起使用。       

        本文是 QT CTK开发 第六篇文章,演示了

    CTK 开发优点
    降低复杂性:使用CTK开发只需进行插件开发,插件隐藏了内部实现,开发变得更加简单,因为只需要实现功能接口即可。
    可复用:标准化的组件模型,一个插件多个软件使用。
    版本控制:所有插件都经过严格的版本控制,只有能够协作的插件才会被连接在一起。
    动态更新:OSGi组件模型是一个动态模型,插件可以在不关闭整个系统的情况下被安装、启动、停止、更新和卸载。
    自适应:OSGI动态服务模型允许插件找出系统中可用的功能,并调整它们所能提供的功能,使得代码更加灵活, 并且能够更好地适应变化。
    透明性:插件和服务是CTK插件环境中的一等公民。管理API提供了对插件的内部状态的访问,以及插件之间的连接方式。
    开发简单:CTK插件相关的API非常简单,核心API不到25个类。核心API足以编写插件、安装、启动、停止、更新和卸载,并且还包含了所有的监听类。
    懒加载:插件可以用饿汉式启动,但是也可以被配置为仅当其它插件使用它们时才启动。服务可以被注册,但只有在使用时才创建。懒加载场景可以节省大量的运行时成本。
    非独占性:CTK Plugin Framework不会接管整个应用程序,可以选择性地将所提供的功能暴露给应用程序的某些部分。
    非侵入:在一个CTK插件环境中,不同插件均有自己的环境。插件可以使用任何设施,框架对此并无限制。

    CTK Plugin Framework不仅仅是组件的标准,还指定了如何安装和管理组件的API。API可以被插件用来提供一个管理代理,管理代理可以非常简单,如命令shell、图形桌面应用程序、Amazon EC2的云计算接口、或IBM Tivoli管理系统。标准化的管理API 使得在现有和未来的系统中集成CTK Plugin Framework变得非常容易。
 

© www.dreambegins.vip 保留所有权利

作者:双子座断点 CSDN

未经许可,禁止任何形式的转载、复制或引用。如出现盗版、未授权转载、本人有权对为许可网站、个人作者进行侵权投诉权利。

创作不易 尊重劳动成果

QT CTK插件开发(六) 多对一插件目录

1 项目结构

 2 QCTKPluginSingleCTK

2.1  qctkpluginsinglectk

2.2 qctkpluginsingleimplctk

2.3 pri文件

2.4 pro

2.5 元数据

3 QCTKPluginSingleQT

3.1 qctkpluginsingleqt

3.2 qctkpluginsingleimplqt

3.3 pri

3.4 pro

3.5 元数据

4 QCTKPluginGatherAPP

5 下载链接

6 其它系列文章


1 项目结构

 2 QCTKPluginSingleCTK

2.1  qctkpluginsinglectk

#ifndef QCTKPLUGINSINGLECTK_H
#define QCTKPLUGINSINGLECTK_H

#include <ctkPluginActivator.h>
#include "qctkpluginsingleimplctk.h"
#include <QtDebug>
class QCTKPluginSingleCTK: public QObject, public ctkPluginActivator
{
    Q_OBJECT
    Q_INTERFACES(ctkPluginActivator)
    Q_PLUGIN_METADATA(IID "QCTKPluginSingleCTK")
public:
    void start(ctkPluginContext* context);
    void stop(ctkPluginContext* context);
private:
    QCTKPluginSingleImplCTK *m_pImpl;
};

#endif // QCTKPLUGINSINGLECTK_H



#include "qctkpluginsinglectk.h"


void QCTKPluginSingleCTK::start(ctkPluginContext* context)
{
    ctkDictionary properties;
    properties.insert(ctkPluginConstants::SERVICE_RANKING, 1);
    properties.insert("name", "Qt");

    m_pImpl = new QCTKPluginSingleImplCTK();
    context->registerService<QCTKPluginSingleImplCTK>(m_pImpl, properties);
}

void QCTKPluginSingleCTK::stop(ctkPluginContext* context)
{
    Q_UNUSED(context)

    delete m_pImpl;
}

2.2 qctkpluginsingleimplctk

#ifndef QCTKPLUGINSINGLEIMPLCTK_H
#define QCTKPLUGINSINGLEIMPLCTK_H

#include <QObject>
#include <QtDebug>
#include "QCTKPluginSingleService.h"

class QCTKPluginSingleImplCTK: public QObject, public QCTKPluginSingleService
{
    Q_OBJECT
    Q_INTERFACES(QCTKPluginSingleService)
public:
    QCTKPluginSingleImplCTK();
    void welcome() Q_DECL_OVERRIDE;
};

#endif // QCTKPLUGINSINGLEIMPLCTK_H



#include "qctkpluginsingleimplctk.h"

QCTKPluginSingleImplCTK::QCTKPluginSingleImplCTK()
{

}

void QCTKPluginSingleImplCTK::welcome()
{
    qDebug() << "QCTKPluginSingle CTK!";
}

2.3 pri文件

# CTK 相关库所在路径(例如:CTKCore.lib、CTKWidgets.lib)
CTK_LIB_PATH = E:\CTK\CTK-build\CTK-build\bin\Release

INCLUDEPATH += E:\CTK\CTK-master\Libs\CommandLineModules
INCLUDEPATH += E:\CTK\CTK-master\Libs\Core
INCLUDEPATH += E:\CTK\CTK-master\Libs\DICOM
INCLUDEPATH += E:\CTK\CTK-master\Libs\ImageProcessing
INCLUDEPATH += E:\CTK\CTK-master\Libs\PluginFramework
INCLUDEPATH += E:\CTK\CTK-master\Libs\QtTesting
INCLUDEPATH += E:\CTK\CTK-master\Libs\Scripting
INCLUDEPATH += E:\CTK\CTK-master\Libs\Testing
INCLUDEPATH += E:\CTK\CTK-master\Libs\Visualization
INCLUDEPATH += E:\CTK\CTK-master\Libs\Widgets
INCLUDEPATH += E:\CTK\CTK-master\Libs\XNAT

INCLUDEPATH += E:\CTK\CTK-build\CTK-build\Libs\Core
INCLUDEPATH += E:\CTK\CTK-build\CTK-build\Libs\Widgets
INCLUDEPATH += E:\CTK\CTK-build\CTK-build\Libs\PluginFramework


# 相关库文件(CTKCore.lib、CTKWidgets.lib)
LIBS += -L$$CTK_LIB_PATH -lCTKCore -lCTKWidgets




# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../CTK/CTK-build/CTK-build/bin/release/ -lCTKCore
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../CTK/CTK-build/CTK-build/bin/debug/ -lCTKCore
else:unix: LIBS += -L$$PWD/../../../CTK/CTK-build/CTK-build/bin/ -lCTKCore

INCLUDEPATH += $$PWD/../../../CTK/CTK-build/CTK-build/bin/Release
DEPENDPATH += $$PWD/../../../CTK/CTK-build/CTK-build/bin/Release

win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../CTK/CTK-build/CTK-build/bin/release/ -lCTKWidgets
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../CTK/CTK-build/CTK-build/bin/debug/ -lCTKWidgets
else:unix: LIBS += -L$$PWD/../../../CTK/CTK-build/CTK-build/bin/ -lCTKWidgets

INCLUDEPATH += $$PWD/../../../CTK/CTK-build/CTK-build/bin/Release
DEPENDPATH += $$PWD/../../../CTK/CTK-build/CTK-build/bin/Release

win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../CTK/CTK-build/CTK-build/bin/release/ -lCTKWidgetsPlugins
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../CTK/CTK-build/CTK-build/bin/debug/ -lCTKWidgetsPlugins
else:unix: LIBS += -L$$PWD/../../../CTK/CTK-build/CTK-build/bin/ -lCTKWidgetsPlugins

INCLUDEPATH += $$PWD/../../../CTK/CTK-build/CTK-build/bin/Release
DEPENDPATH += $$PWD/../../../CTK/CTK-build/CTK-build/bin/Release

win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../CTK/CTK-build/CTK-build/bin/release/ -lCTKCoreCppTests
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../CTK/CTK-build/CTK-build/bin/debug/ -lCTKCoreCppTests
else:unix: LIBS += -L$$PWD/../../../CTK/CTK-build/CTK-build/bin/ -lCTKCoreCppTests

INCLUDEPATH += $$PWD/../../../CTK/CTK-build/CTK-build/bin/Release
DEPENDPATH += $$PWD/../../../CTK/CTK-build/CTK-build/bin/Release

win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../CTK/CTK-build/CTK-build/bin/release/ -lCTKDummyPlugin
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../CTK/CTK-build/CTK-build/bin/debug/ -lCTKDummyPlugin
else:unix: LIBS += -L$$PWD/../../../CTK/CTK-build/CTK-build/bin/ -lCTKDummyPlugin

INCLUDEPATH += $$PWD/../../../CTK/CTK-build/CTK-build/bin/Release
DEPENDPATH += $$PWD/../../../CTK/CTK-build/CTK-build/bin/Release

win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../CTK/CTK-build/CTK-build/bin/release/ -lCTKPluginFramework
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../CTK/CTK-build/CTK-build/bin/debug/ -lCTKPluginFramework
else:unix: LIBS += -L$$PWD/../../../CTK/CTK-build/CTK-build/bin/ -lCTKPluginFramework

INCLUDEPATH += $$PWD/../../../CTK/CTK-build/CTK-build/bin/Release
DEPENDPATH += $$PWD/../../../CTK/CTK-build/CTK-build/bin/Release

win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../CTK/CTK-build/CTK-build/bin/release/ -lCTKPluginFrameworkTestUtil
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../CTK/CTK-build/CTK-build/bin/debug/ -lCTKPluginFrameworkTestUtil
else:unix: LIBS += -L$$PWD/../../../CTK/CTK-build/CTK-build/bin/ -lCTKPluginFrameworkTestUtil

INCLUDEPATH += $$PWD/../../../CTK/CTK-build/CTK-build/bin/Release
DEPENDPATH += $$PWD/../../../CTK/CTK-build/CTK-build/bin/Release

2.4 pro

QT       += core gui widgets

TEMPLATE = lib
DEFINES += QCTKPLUGINSINGLECTK_LIBRARY

CONFIG += c++11

# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

SOURCES += \
    qctkpluginsinglectk.cpp \
    qctkpluginsingleimplctk.cpp

HEADERS += \
    qctkpluginsinglectk.h \
    qctkpluginsingleimplctk.h

DESTDIR = ../../plugins

file.path = $$DESTDIR
file.files = MANIFEST.MF
INSTALLS += file

include(../CTKPath.pri )

RESOURCES += \
    QCTKPluginSingleCTK.qrc

INCLUDEPATH += E:\QT\QCTKView\QCTKPluginGather

# Default rules for deployment.
unix {
    target.path = /usr/lib
}
!isEmpty(target.path): INSTALLS += target







2.5 元数据

MANIFEST.MF

Plugin-SymbolicName:QCTKPluginSingleCTK
Plugin-Version:1.0.0
Plugin-Number:100 #元数据

3 QCTKPluginSingleQT

3.1 qctkpluginsingleqt

#ifndef QCTKPLUGINSINGLEQT_H
#define QCTKPLUGINSINGLEQT_H

#include <ctkPluginActivator.h>
#include "qctkpluginsingleimplqt.h"
#include <QtDebug>

class  QCTKPluginSingleQT: public QObject, public ctkPluginActivator
{
    Q_OBJECT
    Q_INTERFACES(ctkPluginActivator)
    Q_PLUGIN_METADATA(IID "QCTKPluginSingleQT")
public:
    void start(ctkPluginContext* context);
    void stop(ctkPluginContext* context);
private:
    QCTKPluginSingleImplQT *m_pImpl;
};

#endif // QCTKPLUGINSINGLEQT_H


#include "qctkpluginsingleqt.h"




void QCTKPluginSingleQT::start(ctkPluginContext* context)
{
    ctkDictionary properties;
    properties.insert(ctkPluginConstants::SERVICE_RANKING, 1);
    properties.insert("name", "Qt");

    m_pImpl = new QCTKPluginSingleImplQT();
    context->registerService<QCTKPluginSingleImplQT>(m_pImpl, properties);
}

void QCTKPluginSingleQT::stop(ctkPluginContext* context)
{
    Q_UNUSED(context)

    delete m_pImpl;
}



3.2 qctkpluginsingleimplqt

#ifndef QCTKPLUGINSINGLEIMPLQT_H
#define QCTKPLUGINSINGLEIMPLQT_H

#include <QObject>
#include <QtDebug>

#include "QCTKPluginSingleService.h"

class ctkPluginContext;
class QCTKPluginSingleImplQT: public QObject, public QCTKPluginSingleService
{
    Q_OBJECT
    Q_INTERFACES(QCTKPluginSingleService)
public:
    QCTKPluginSingleImplQT();

    void welcome() Q_DECL_OVERRIDE;
};

#endif // QCTKPLUGINSINGLEIMPLQT_H



#include "qctkpluginsingleimplqt.h"

QCTKPluginSingleImplQT::QCTKPluginSingleImplQT()
{

}


void QCTKPluginSingleImplQT::welcome()
{
    qDebug() << "QCTKPluginSingle Qt!";
}

3.3 pri

# CTK 相关库所在路径(例如:CTKCore.lib、CTKWidgets.lib)
CTK_LIB_PATH = E:\CTK\CTK-build\CTK-build\bin\Release

INCLUDEPATH += E:\CTK\CTK-master\Libs\CommandLineModules
INCLUDEPATH += E:\CTK\CTK-master\Libs\Core
INCLUDEPATH += E:\CTK\CTK-master\Libs\DICOM
INCLUDEPATH += E:\CTK\CTK-master\Libs\ImageProcessing
INCLUDEPATH += E:\CTK\CTK-master\Libs\PluginFramework
INCLUDEPATH += E:\CTK\CTK-master\Libs\QtTesting
INCLUDEPATH += E:\CTK\CTK-master\Libs\Scripting
INCLUDEPATH += E:\CTK\CTK-master\Libs\Testing
INCLUDEPATH += E:\CTK\CTK-master\Libs\Visualization
INCLUDEPATH += E:\CTK\CTK-master\Libs\Widgets
INCLUDEPATH += E:\CTK\CTK-master\Libs\XNAT

INCLUDEPATH += E:\CTK\CTK-build\CTK-build\Libs\Core
INCLUDEPATH += E:\CTK\CTK-build\CTK-build\Libs\Widgets
INCLUDEPATH += E:\CTK\CTK-build\CTK-build\Libs\PluginFramework


# 相关库文件(CTKCore.lib、CTKWidgets.lib)
LIBS += -L$$CTK_LIB_PATH -lCTKCore -lCTKWidgets




# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../CTK/CTK-build/CTK-build/bin/release/ -lCTKCore
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../CTK/CTK-build/CTK-build/bin/debug/ -lCTKCore
else:unix: LIBS += -L$$PWD/../../../CTK/CTK-build/CTK-build/bin/ -lCTKCore

INCLUDEPATH += $$PWD/../../../CTK/CTK-build/CTK-build/bin/Release
DEPENDPATH += $$PWD/../../../CTK/CTK-build/CTK-build/bin/Release

win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../CTK/CTK-build/CTK-build/bin/release/ -lCTKWidgets
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../CTK/CTK-build/CTK-build/bin/debug/ -lCTKWidgets
else:unix: LIBS += -L$$PWD/../../../CTK/CTK-build/CTK-build/bin/ -lCTKWidgets

INCLUDEPATH += $$PWD/../../../CTK/CTK-build/CTK-build/bin/Release
DEPENDPATH += $$PWD/../../../CTK/CTK-build/CTK-build/bin/Release

win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../CTK/CTK-build/CTK-build/bin/release/ -lCTKWidgetsPlugins
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../CTK/CTK-build/CTK-build/bin/debug/ -lCTKWidgetsPlugins
else:unix: LIBS += -L$$PWD/../../../CTK/CTK-build/CTK-build/bin/ -lCTKWidgetsPlugins

INCLUDEPATH += $$PWD/../../../CTK/CTK-build/CTK-build/bin/Release
DEPENDPATH += $$PWD/../../../CTK/CTK-build/CTK-build/bin/Release

win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../CTK/CTK-build/CTK-build/bin/release/ -lCTKCoreCppTests
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../CTK/CTK-build/CTK-build/bin/debug/ -lCTKCoreCppTests
else:unix: LIBS += -L$$PWD/../../../CTK/CTK-build/CTK-build/bin/ -lCTKCoreCppTests

INCLUDEPATH += $$PWD/../../../CTK/CTK-build/CTK-build/bin/Release
DEPENDPATH += $$PWD/../../../CTK/CTK-build/CTK-build/bin/Release

win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../CTK/CTK-build/CTK-build/bin/release/ -lCTKDummyPlugin
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../CTK/CTK-build/CTK-build/bin/debug/ -lCTKDummyPlugin
else:unix: LIBS += -L$$PWD/../../../CTK/CTK-build/CTK-build/bin/ -lCTKDummyPlugin

INCLUDEPATH += $$PWD/../../../CTK/CTK-build/CTK-build/bin/Release
DEPENDPATH += $$PWD/../../../CTK/CTK-build/CTK-build/bin/Release

win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../CTK/CTK-build/CTK-build/bin/release/ -lCTKPluginFramework
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../CTK/CTK-build/CTK-build/bin/debug/ -lCTKPluginFramework
else:unix: LIBS += -L$$PWD/../../../CTK/CTK-build/CTK-build/bin/ -lCTKPluginFramework

INCLUDEPATH += $$PWD/../../../CTK/CTK-build/CTK-build/bin/Release
DEPENDPATH += $$PWD/../../../CTK/CTK-build/CTK-build/bin/Release

win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../CTK/CTK-build/CTK-build/bin/release/ -lCTKPluginFrameworkTestUtil
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../CTK/CTK-build/CTK-build/bin/debug/ -lCTKPluginFrameworkTestUtil
else:unix: LIBS += -L$$PWD/../../../CTK/CTK-build/CTK-build/bin/ -lCTKPluginFrameworkTestUtil

INCLUDEPATH += $$PWD/../../../CTK/CTK-build/CTK-build/bin/Release
DEPENDPATH += $$PWD/../../../CTK/CTK-build/CTK-build/bin/Release

3.4 pro

QT       += core gui widgets

TEMPLATE = lib
DEFINES += QCTKPLUGINSINGLEQT_LIBRARY

CONFIG += c++11

# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

SOURCES += \
    qctkpluginsingleimplqt.cpp \
    qctkpluginsingleqt.cpp

HEADERS += \
    qctkpluginsingleimplqt.h \
    qctkpluginsingleqt.h

DESTDIR = ../../plugins

file.path = $$DESTDIR
file.files = MANIFEST.MF
INSTALLS += file

include(../CTKPath.pri )

RESOURCES += \
    QCTKPluginSingleQT.qrc

INCLUDEPATH += E:\QT\QCTKView\QCTKPluginGather

# Default rules for deployment.
unix {
    target.path = /usr/lib
}
!isEmpty(target.path): INSTALLS += target

3.5 元数据

MANIFEST.MF

Plugin-SymbolicName:QCTKPluginSingleQT
Plugin-Version:1.0.0
Plugin-Number:100 #元数据

4 QCTKPluginGatherAPP

核心代码

#include "mainwindow.h"

#include <QApplication>


#include <QDirIterator>
#include <QtDebug>

#include "QCTKPluginSingleService.h"

#include <ctkPluginFrameworkFactory.h>
#include <ctkPluginFramework.h>
#include <ctkPluginException.h>
#include <ctkPluginContext.h>

#pragma execution_character_set("utf-8")

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;



    ctkPluginFrameworkFactory frameWorkFactory;
    QSharedPointer<ctkPluginFramework> framework = frameWorkFactory.getFramework();
    try {
        // 初始化并启动插件框架
        framework->init();
        framework->start();
        qDebug() << "CTK Plugin Framework start ...";
    } catch (const ctkPluginException &e) {
        qDebug() << "Failed to initialize the plugin framework: " << e.what();
        return -1;
    }

    qDebug() << "********************";

    // 获取插件上下文
    ctkPluginContext* context = framework->getPluginContext();

    // 获取插件所在位置
    QString path = "E:\QT\QCTKView\QCTKPluginGather\plugins";

    // 遍历路径下的所有插件
    QDirIterator itPlugin(path, QStringList() << "*.dll" << "*.so", QDir::Files);
    while (itPlugin.hasNext()) {
        QString strPlugin = itPlugin.next();
        try {
            // 安装插件
            QSharedPointer<ctkPlugin> plugin = context->installPlugin(QUrl::fromLocalFile(strPlugin));
            // 启动插件
            plugin->start(ctkPlugin::START_TRANSIENT);
            qDebug() << "Plugin start:" << QFileInfo(strPlugin).fileName();
        } catch (const ctkPluginException &e) {
            qDebug() << "Failed to start plugin" << e.what();
            return -1;
        }
    }

    qDebug() << "********************";

    // 1. 获取所有服务
    QList<ctkServiceReference> refs = context->getServiceReferences<QCTKPluginSingleService>();
    foreach (ctkServiceReference ref, refs) {
        if (ref) {
            qDebug() << "Name:" << ref.getProperty("name").toString()
                     <<  "Service ranking:" << ref.getProperty(ctkPluginConstants::SERVICE_RANKING).toLongLong()
                      << "Service id:" << ref.getProperty(ctkPluginConstants::SERVICE_ID).toLongLong();
            QCTKPluginSingleService* service = qobject_cast<QCTKPluginSingleService *>(context->getService(ref));
            if (service != Q_NULLPTR)
                service->welcome();
        }
    }

    qDebug() << "********************";

    // 2. 使用过滤表达式,获取感兴趣的服务
    refs = context->getServiceReferences<QCTKPluginSingleService>("(&(name=CTK))");
    foreach (ctkServiceReference ref, refs) {
        if (ref) {
            QCTKPluginSingleService* service = qobject_cast<QCTKPluginSingleService *>(context->getService(ref));
            if (service != Q_NULLPTR)
                service->welcome();
        }
    }

    qDebug() << "********************";

    // 3. 获取某一个服务(由 Service Ranking 和 Service ID 决定)
    ctkServiceReference ref = context->getServiceReference<QCTKPluginSingleService>();
    if (ref) {
        QCTKPluginSingleService* service = qobject_cast<QCTKPluginSingleService *>(context->getService(ref));
        if (service != Q_NULLPTR)
            service->welcome();
    }



    w.show();
    return a.exec();
}



PRO

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++11

# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

SOURCES += \
    main.cpp \
    mainwindow.cpp

HEADERS += \
    mainwindow.h

FORMS += \
    mainwindow.ui

include(../CTKPath.pri )
INCLUDEPATH += E:\QT\QCTKView\QCTKPluginGather

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

# CTK 相关库所在路径(例如:CTKCore.lib、CTKWidgets.lib)
CTK_LIB_PATH = E:\CTK\CTK-build\CTK-build\bin\Release

INCLUDEPATH += E:\CTK\CTK-master\Libs\CommandLineModules
INCLUDEPATH += E:\CTK\CTK-master\Libs\Core
INCLUDEPATH += E:\CTK\CTK-master\Libs\DICOM
INCLUDEPATH += E:\CTK\CTK-master\Libs\ImageProcessing
INCLUDEPATH += E:\CTK\CTK-master\Libs\PluginFramework
INCLUDEPATH += E:\CTK\CTK-master\Libs\QtTesting
INCLUDEPATH += E:\CTK\CTK-master\Libs\Scripting
INCLUDEPATH += E:\CTK\CTK-master\Libs\Testing
INCLUDEPATH += E:\CTK\CTK-master\Libs\Visualization
INCLUDEPATH += E:\CTK\CTK-master\Libs\Widgets
INCLUDEPATH += E:\CTK\CTK-master\Libs\XNAT

INCLUDEPATH += E:\CTK\CTK-build\CTK-build\Libs\Core
INCLUDEPATH += E:\CTK\CTK-build\CTK-build\Libs\Widgets
INCLUDEPATH += E:\CTK\CTK-build\CTK-build\Libs\PluginFramework


# 相关库文件(CTKCore.lib、CTKWidgets.lib)
LIBS += -L$$CTK_LIB_PATH -lCTKCore -lCTKWidgets




# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../CTK/CTK-build/CTK-build/bin/release/ -lCTKCore
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../CTK/CTK-build/CTK-build/bin/debug/ -lCTKCore
else:unix: LIBS += -L$$PWD/../../../CTK/CTK-build/CTK-build/bin/ -lCTKCore

INCLUDEPATH += $$PWD/../../../CTK/CTK-build/CTK-build/bin/Release
DEPENDPATH += $$PWD/../../../CTK/CTK-build/CTK-build/bin/Release

win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../CTK/CTK-build/CTK-build/bin/release/ -lCTKWidgets
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../CTK/CTK-build/CTK-build/bin/debug/ -lCTKWidgets
else:unix: LIBS += -L$$PWD/../../../CTK/CTK-build/CTK-build/bin/ -lCTKWidgets

INCLUDEPATH += $$PWD/../../../CTK/CTK-build/CTK-build/bin/Release
DEPENDPATH += $$PWD/../../../CTK/CTK-build/CTK-build/bin/Release

win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../CTK/CTK-build/CTK-build/bin/release/ -lCTKWidgetsPlugins
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../CTK/CTK-build/CTK-build/bin/debug/ -lCTKWidgetsPlugins
else:unix: LIBS += -L$$PWD/../../../CTK/CTK-build/CTK-build/bin/ -lCTKWidgetsPlugins

INCLUDEPATH += $$PWD/../../../CTK/CTK-build/CTK-build/bin/Release
DEPENDPATH += $$PWD/../../../CTK/CTK-build/CTK-build/bin/Release

win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../CTK/CTK-build/CTK-build/bin/release/ -lCTKCoreCppTests
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../CTK/CTK-build/CTK-build/bin/debug/ -lCTKCoreCppTests
else:unix: LIBS += -L$$PWD/../../../CTK/CTK-build/CTK-build/bin/ -lCTKCoreCppTests

INCLUDEPATH += $$PWD/../../../CTK/CTK-build/CTK-build/bin/Release
DEPENDPATH += $$PWD/../../../CTK/CTK-build/CTK-build/bin/Release

win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../CTK/CTK-build/CTK-build/bin/release/ -lCTKDummyPlugin
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../CTK/CTK-build/CTK-build/bin/debug/ -lCTKDummyPlugin
else:unix: LIBS += -L$$PWD/../../../CTK/CTK-build/CTK-build/bin/ -lCTKDummyPlugin

INCLUDEPATH += $$PWD/../../../CTK/CTK-build/CTK-build/bin/Release
DEPENDPATH += $$PWD/../../../CTK/CTK-build/CTK-build/bin/Release

win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../CTK/CTK-build/CTK-build/bin/release/ -lCTKPluginFramework
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../CTK/CTK-build/CTK-build/bin/debug/ -lCTKPluginFramework
else:unix: LIBS += -L$$PWD/../../../CTK/CTK-build/CTK-build/bin/ -lCTKPluginFramework

INCLUDEPATH += $$PWD/../../../CTK/CTK-build/CTK-build/bin/Release
DEPENDPATH += $$PWD/../../../CTK/CTK-build/CTK-build/bin/Release

win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../CTK/CTK-build/CTK-build/bin/release/ -lCTKPluginFrameworkTestUtil
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../CTK/CTK-build/CTK-build/bin/debug/ -lCTKPluginFrameworkTestUtil
else:unix: LIBS += -L$$PWD/../../../CTK/CTK-build/CTK-build/bin/ -lCTKPluginFrameworkTestUtil

INCLUDEPATH += $$PWD/../../../CTK/CTK-build/CTK-build/bin/Release
DEPENDPATH += $$PWD/../../../CTK/CTK-build/CTK-build/bin/Release

5 下载链接

https://mp.csdn.net/mp_download/manage/download/UpDetailed 密码: ctk123456

6 其它系列文章

QT CTK插件框架 (一 下载编译)_双子座断点的博客-CSDN博客

QT CTK控件 CTK开发(二)_双子座断点的博客-CSDN博客

QT 创建插件 CTK开发(三)_双子座断点的博客-CSDN博客

QT 插件通信接口调用 CTK开发(四)_双子座断点的博客-CSDN博客

说明:未完待续 作者近期会尽快整理涉及该系列文章 尽快完结该系列也会推出相关软件程序等...

对于之前的文章也会一直继续优化等...
 

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/617747.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

基于jupyter的逻辑回归练习

文章目录 练习2&#xff1a;逻辑回归介绍1 Logistic回归1.1 数据可视化1.2 实现1.2.1 Sigmoid函数1.2.2 代价函数和梯度1.2.2.1 代价函数1.2.2.2 梯度下降 1.2.3 寻找最优参数1.2.4 评估逻辑回归 2 正则化逻辑回归2.1 数据可视化2.2 特征映射2.3 代价函数和梯度 2.4 寻找最优参…

腾讯云618云服务器优惠活动价格表

2023年腾讯云618年中促销活动已经正式开始了&#xff0c;腾讯云多款云服务都有特惠&#xff0c;下面给大家分享腾讯云618云服务器优惠活动价格表&#xff0c;记得抓住这次上云好时机&#xff01; 目录 一、腾讯云618活动入口 二、轻量应用服务器优惠价格表 三、CVM云服务器优…

【连续介质力学】二阶张量的图像表示

二阶张量在特定方向的投影 法向和切向分量 二阶张量T投影到 n ^ \hat n n^方向的结果是 t ⃗ ( n ^ ) T ⋅ n ^ \vec t^{(\hat n)}T \cdot \hat n t (n^)T⋅n^&#xff0c;其中 t ⃗ ( n ^ ) \vec t^{(\hat n)} t (n^)可以分解成&#xff1a; t ⃗ ( n ^ ) T ⃗ N T ⃗ S…

指针(三)

文章内容 1. 字符指针 2. 数组指针 3. 指针数组 文章内容 1. 字符指针 指针的概念&#xff1a; 1. 指针就是个变量&#xff0c;用来存放地址&#xff0c;地址唯一标识一块内存空间。 2. 指针的大小是固定的4/8个字节&#xff08;32位平台/64位平台&#xff09;。 3. 指针…

适配器stack和queue

目录 什么是适配器 模拟实现stack stack的特性 STL中stack的基本框架 接口实现 模拟实现queue queue的特性 STL中queue的框架 什么是适配器 适配器&#xff1a;所谓适配&#xff0c;适配的是容器(vector,list,deque....) 也就是不管是什么容器&#xff0c;都可以套用适…

chatgpt赋能python:Python如何设置输入的SEO

Python如何设置输入的SEO Python是一种高级的编程语言&#xff0c;具有容易上手、可扩展和开源等特点&#xff0c;因此在软件开发过程中得到广泛的应用。然而&#xff0c;如果您想让您的Python项目在搜索引擎上获得更好的排名和流量&#xff0c;您需要考虑如何设置输入的SEO。…

二叉搜索树(Binary Seach Tree)模拟实现

目录 二叉搜索树的性质 二叉搜索树的实现 结点类 接口类(BSTree) 二叉搜索树的插入(insert) 二叉搜索树的查找(find) 二叉搜索树删除(erase) 第二种、删除的结点右子树为空 第三种、删除的结点左子树为空 第四种、删除的结点左右都不为空 实现 二叉搜索树模拟实现代…

基于jupyter的轮廓检测及功能

文章目录 一、实验介绍二、实验步骤三、实验任务任务一&#xff1a;轮廓特征练习一: 找到每个轮廓的方向任务二&#xff1a;边界矩形练习二: 围绕轮廓裁剪图像 总结 一、实验介绍 1. 实验内容 本实验将学习轮廓检测及功能。 2. 实验要点 生成二进制图像来查找轮廓找到并画出…

kotlin函数返回函数

kotlin函数返回函数 https://blog.csdn.net/zhangphil/category_12220817.htmlhttps://blog.csdn.net/zhangphil/category_12220817.html 例1&#xff1a; // func返回匿名函数 fun func(msg: String): (String, Int) -> String {println("func函数 msg:$msg")/…

电能管理系统多功能电力仪表的应用 安科瑞 许敏

摘 要&#xff1a;基于车间用电设备的电能管理系统架构思路及实施方法&#xff0c;从硬件和软件方面对此方法进行了阐述。对车间旧设备改造以及新的电能管理系统提供一种思路和便捷的方法。 关键词&#xff1a;电能管理系统&#xff1b;多功能电力仪表&#xff1b;PLC&#x…

Azure Log Analytics:与Power BI集成

注&#xff1a;本文最初发布于https://d-bi.gitee.io, 2023年6月迁移至CSDN 前述 Azure Log Analytics是Azure Monitor中的一项分析服务。本文将讲述通过Log Analytics与Power BI集成的方式&#xff0c;获取Power BI工作区内的日志信息&#xff0c;包括各PBI数据集的CPU消耗&a…

6/5~6/6总结

创建存储过程 DELIMITER // CREATE PROCEDURE usingid() BEGIN SELECT AVG(id) FROM user; END // DELIMITER ; 要用DELIMITER //指定结束符为 "//", 要调用该存储过程&#xff1a; CAll usingid; 创建成功后在navicat里面的函数界面可以看见刚刚创建的存储过程…

【TCP/IP】IP地址与域名之间的转换 - gethostbyname 和 gethostbyaddr函数

目录 域名系统 DNS服务器 IP地址和域名之间的转换 通过域名获取IP地址 通过IP地址获取域名 域名系统 域名系统&#xff08;英文&#xff1a;Domain Name System&#xff0c;缩写&#xff1a;DNS&#xff09;是互联网的一项服务。它作为将域名和IP地址相互映射的一个分布式…

chatgpt赋能python:Python如何竖直输出?

Python如何竖直输出&#xff1f; Python作为一种功能强大的编程语言&#xff0c;在数据分析、人工智能、Web开发等领域得到广泛应用。不过&#xff0c;对于一些初学者或者日常编程较少的开发者来说&#xff0c;可能会遇到一些问题&#xff0c;例如如何竖直输出。 在Python中&…

软件过程与管理——民宿管理系统的项目实践报告(文档+ppt+图表源文件)

目录 一、题目分析与设计 二、评分标准 三、文档目录 四、文档下载 一、题目分析与设计 1、团队组织建设 同学们以3-5人为一组&#xff0c;最多5人一组&#xff0c;每组选择一个具体的软件项目&#xff0c;如现进行的个人毕业设计题目等为主题&#xff0c;要求项目的工作…

量子模拟器中的“弯曲时空”

光子盒研究院出品 当你想解释宇宙尺度的现象时&#xff0c;相对论很有效&#xff1a;比如黑洞碰撞时产生的引力波&#xff1b;量子理论在描述粒子尺度的现象时效果很好&#xff08;比如原子中单个电子的行为&#xff09;。但是&#xff0c;将这两者以一种完全令人满意的方式结合…

【SpinalHDL快速入门】4.6、复合类型之Vec

文章目录 1.1、描述1.2、声明1.2.1、实例 1.3、运算符1.3.1、比较&#xff08;Comparison&#xff09;1.3.2、类型转换&#xff08;Type cast&#xff09;1.3.3、杂项&#xff08;Misc&#xff09;1.3.4、Lib辅助函数&#xff08;Lib helper functions&#xff09; 1.1、描述 …

直播签到功能(互动功能发起端JS-SDK)

功能概述 本功能只支持角色为讲师/嘉宾/助教/管理员的用户进行发起和停止等操作。发起签到时可自定义设置签到时长和签到提示语。 图 / 讲师在直播客户端软件f中操作界面 图 / 学员直播观看页弹出签到界面 代码示例 注意&#xff0c;在开始以下步骤前需要先进行全局初始化设置…

chatgpt赋能python:Python-如何快速高效地求两数之和

Python - 如何快速高效地求两数之和 介绍 Python 是一种高级编程语言&#xff0c;适用于各种领域的软件开发。本文将介绍使用 Python 完成两个数字之和的操作。Python 以其清晰、简洁、易于学习和使用的特性闻名于世&#xff0c;既能作为脚本语言&#xff0c;又能进行面向对象…

基于stm32的超声波测距

文章目录 一、HC-SR04超声波测距模块说明1、产品特点2、电气参数3、HC-SR04超声波测距模块4、超声波时序图 二、 CUBEMX配置三、keil配置代码 模块选择&#xff1a; stm32f103c8芯片 HC-SR04超声波测距模块 一、HC-SR04超声波测距模块说明 1、产品特点 HC-SR04 超声波测距模块…