系列索引:CTK框架入门教程索引
插件框架CTK插件框架包含启动器和插件。其中启动器负责启动插件,以exe格式表示;插件负责提供服务,以dll格式表示。
开发框架CTK开发框架包含一个Qt子工程、一个命令行程序、一个或者多个插件工程。
子工程CTK子工程用于管理启动器工程和插件工程。标准的Qt子工程,内容如下:
1 2 3 4 5 6 TEMPLATE = subdirs CONFIG += ordered SUBDIRS += \ launcher
添加新工程就添加新模块工程。
启动器启动器以exe表示,创建一个console工程。工程配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 QT += core QT -= gui TARGET = test CONFIG += console CONFIG -= app_bundle win32:{ INCLUDEPATH += \ D:\CTK-2023.07.13\Libs\Core \ D:\CTK-2023.07.13\Libs\PluginFramework \ D:\CTK-2023.07.13\build\CTK-build\Libs\PluginFramework \ D:\CTK-2023.07.13\build\CTK-build\Libs\Core LIBS += -LD:\CTK-2023.07.13\build\CTK-build\bin\Debug \ -lCTKCore -lCTKPluginFramework } unix:{ INCLUDEPATH += \ /home/jackey/Downloads/CTK-2023.07.13/Libs/Core \ /home/jackey/Downloads/CTK-2023.07.13/Libs/PluginFramework \ /home/jackey/Downloads/CTK-2023.07.13/build/CTK-build/Libs/PluginFramework \ /home/jackey/Downloads/CTK-2023.07.13/build/CTK-build/Libs/Core LIBS += -L/home/jackey/Downloads/CTK-2023.07.13/build/CTK-build/bin \ -lCTKCore -lCTKPluginFramework } SOURCES += \ main.cpp
在源码中调用框架
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 #include <QCoreApplication> #include <ctkPluginFrameworkFactory.h> #include <ctkPluginFramework.h> #include <ctkPluginException.h> #include <ctkPluginContext.h> #include <QtDebug> #include <QUrl> int main (int argc, char *argv[]) { QCoreApplication a (argc, argv) ; ctkPluginFrameworkFactory frameworkFactory; QSharedPointer<ctkPluginFramework> framework = frameworkFactory.getFramework (); try { framework->init (); framework->start (); qDebug () << "CTK plugin framework start..." ; } catch (const ctkPluginException &e) { qDebug () << "CTK plugin framework init err: " << e.what (); return -1 ; } return a.exec (); }
编译工程为程序
运行执行启动器,终端输出
1 2 3 4 Using database: "D:\\github.com\\CTK\\build\\debug\\configuration\\plugins.db" Using database: "D:\\github.com\\CTK\\build\\debug\\configuration\\plugins.db" Using database: "D:\\github.com\\CTK\\build\\debug\\configuration\\plugins.db" CTK plugin framework start...
程序所在目录自动生成配置文件。
运行依赖启动器运行需要CTK框架依赖库,可以将依赖库复制到启动器目录下,或者在编译时指定依赖库路径。
这里选择自动复制。
1 2 # 编译后执行复制命令 QMAKE_POST_LINK += xcopy /D /F /E /Y \"$${PWD}\\..\\3rd_party\\debug\\bin\" \"..\\..\\debug\"
路径需要使用双引号,否则会报错。
插件信息一下配置给插件添加信息,以便用户查看。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 # 程序信息 CONFIG += skip_target_version_ext #避免dll名称中出现数字 # 版本 VERSION = 1.0.0 # 图标 RC_ICONS = panda.ico #dll没有图标 # 公司名称 QMAKE_TARGET_COMPANY = "jackeylea.com" # 产品名称 QMAKE_TARGET_PRODUCT = "VAPS XT" # 文件说明 QMAKE_TARGET_DESCRIPTION = "Based on Qt 5.15.2 (MSVC 2019, x64)" # 版权 QMAKE_TARGET_COPYRIGHT = "jackeylea © 2025.All rights reserved." # 简体中文 RC_LANG = 0x0004