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 其它系列文章
#ifndef QCTKPLUGINSINGLECTK_H
#define QCTKPLUGINSINGLECTK_H
#include
#include "qctkpluginsingleimplctk.h"
#include
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(m_pImpl, properties);
}
void QCTKPluginSingleCTK::stop(ctkPluginContext* context)
{
Q_UNUSED(context)
delete m_pImpl;
}
#ifndef QCTKPLUGINSINGLEIMPLCTK_H
#define QCTKPLUGINSINGLEIMPLCTK_H
#include
#include
#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!";
}
# 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
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
MANIFEST.MF
Plugin-SymbolicName:QCTKPluginSingleCTK
Plugin-Version:1.0.0
Plugin-Number:100 #元数据
#ifndef QCTKPLUGINSINGLEQT_H
#define QCTKPLUGINSINGLEQT_H
#include
#include "qctkpluginsingleimplqt.h"
#include
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(m_pImpl, properties);
}
void QCTKPluginSingleQT::stop(ctkPluginContext* context)
{
Q_UNUSED(context)
delete m_pImpl;
}
#ifndef QCTKPLUGINSINGLEIMPLQT_H
#define QCTKPLUGINSINGLEIMPLQT_H
#include
#include
#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!";
}
# 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
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
MANIFEST.MF
Plugin-SymbolicName:QCTKPluginSingleQT
Plugin-Version:1.0.0
Plugin-Number:100 #元数据
核心代码
#include "mainwindow.h"
#include
#include
#include
#include "QCTKPluginSingleService.h"
#include
#include
#include
#include
#pragma execution_character_set("utf-8")
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
ctkPluginFrameworkFactory frameWorkFactory;
QSharedPointer 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 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 refs = context->getServiceReferences();
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(context->getService(ref));
if (service != Q_NULLPTR)
service->welcome();
}
}
qDebug() << "********************";
// 2. 使用过滤表达式,获取感兴趣的服务
refs = context->getServiceReferences("(&(name=CTK))");
foreach (ctkServiceReference ref, refs) {
if (ref) {
QCTKPluginSingleService* service = qobject_cast(context->getService(ref));
if (service != Q_NULLPTR)
service->welcome();
}
}
qDebug() << "********************";
// 3. 获取某一个服务(由 Service Ranking 和 Service ID 决定)
ctkServiceReference ref = context->getServiceReference();
if (ref) {
QCTKPluginSingleService* service = qobject_cast(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
https://mp.csdn.net/mp_download/manage/download/UpDetailed 密码: ctk123456
QT CTK插件框架 (一 下载编译)_双子座断点的博客-CSDN博客
QT CTK控件 CTK开发(二)_双子座断点的博客-CSDN博客
QT 创建插件 CTK开发(三)_双子座断点的博客-CSDN博客
QT 插件通信接口调用 CTK开发(四)_双子座断点的博客-CSDN博客
说明:未完待续 作者近期会尽快整理涉及该系列文章 尽快完结该系列也会推出相关软件程序等...
对于之前的文章也会一直继续优化等...