大家好,又见面了,我是你们的朋友全栈君。
用ctk加载插件有两种方法,第一种需要自己创建ctkPluginFramework:
//ctk plugin
ctkPluginFrameworkFactory* ctkFrameWorkFactory = new ctkPluginFrameworkFactory;
QSharedPointer<ctkPluginFramework> framework = ctkFrameWorkFactory->getFramework();
try
{
framework->init();
framework->start();
qDebug() << "[Info] ctkPluginFramework start ...";
}
catch (const ctkPluginException &Exception)
{
qDebug() << QObject::tr("Failed to initialize the plug-in framework: ") << Exception.what();
return 1;
}
//install plugin
ctkPluginContext* pluginContext = framework->getPluginContext();
QSharedPointer<ctkPlugin> Plugin = pluginContext->installPlugin(QUrl::fromLocalFile("。。/liborg_ctk_example.dll"));
Plugin->start(ctkPlugin::START_TRANSIENT);
还有一种比较简单的利用ctkPluginFrameworkLauncher
ctkPluginFrameworkLauncher::addSearchPath(path, true); //添加插件的搜索路径
bool SUCCEEDED;
try
{
SUCCEEDED = ctkPluginFrameworkLauncher::start(pluginSymbolicName); //pluginSybolName为插件的符号名,比如在MF文件中的 Plugin-SymbolicName: org.ctk.example,这里就是“org.ctk.example”
}
catch (ctkPluginException &e)
{
std::cout << "Error in " << pluginSymbolicName << " " << e.message().toStdString() << std::endl;
const ctkException* e2 = e.cause();
if (e2)
std::cout << e2->message().toStdString() << std::endl;
return LOAD_FAILED;
}
catch (ctkRuntimeException &e)
{
std::cout << "Error in " << pluginSymbolicName << " " << e.what() << std::endl;
const ctkException* e2 = e.cause();
if (e2)
std::cout << e2->message().toStdString() << std::endl;
return LOAD_FAILED;
}
catch (...)
{
std::cout << "Error in " << pluginSymbolicName << std::endl;
return UNKNOW_EXCEPTION;
}
获取pluginContext用下面方法
ctkPluginFrameworkLauncher::getPluginContext()
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/134812.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...