[英]How to manage the dependencies of custom Qt plugin (not for Qt Creator)?
I've recently started working with plugins in Qt just for fun. 我最近开始只是为了好玩而在Qt中使用插件。 One thing I still can't figure out is how to define and manage a plugin's dependencies on other plugins (and libraries). 我仍然不知道的一件事是如何定义和管理插件对其他插件(和库)的依赖关系。 I'm using the Plug&Paint example . 我使用的是Plug&Paint示例 。
When it comes to Qt Creator for instance there are two variables that handle this namely QTC_PLUGIN_DEPENDS
(for being dependant on other plugins) and QTC_LIB_DEPENDS
(for being dependant on specific libraries). 例如,当涉及到Qt Creator时 ,有两个变量可以处理此问题,即QTC_PLUGIN_DEPENDS
(用于依赖其他插件)和QTC_LIB_DEPENDS
(用于依赖特定库)。 As an example there is the VcsBase
(version control system base plugin): 例如,有VcsBase
(版本控制系统基础插件):
QTC_PLUGIN_NAME = VcsBase
QTC_LIB_DEPENDS += \ // <--------------------libraries the Qt Creator plugin depends on
aggregation \
cplusplus \
extensionsystem \
utils
QTC_PLUGIN_DEPENDS += \ //<-------------------other plugins the Qt Creator plugin depends on
coreplugin \
texteditor \
projectexplorer \
cpptools \
diffeditor
QTC_PLUGIN_RECOMMENDS += \
cpaster
As you can see it has multiple library and plugin dependencies. 如您所见,它具有多个库和插件依赖性。 From how I understand all this in the IDE all plugins have at least on other plugin dependency namely the coreplugin
. 根据我对IDE中所有这些的了解,所有插件至少都依赖于其他插件依赖项,即coreplugin
。 In addition to that other plugins provide partial functionality to the plugin that depends on these. 除此以外,其他插件还为依赖于这些插件的插件提供了部分功能。
To continue the example we have the Git
, SVN
etc. plugins all of which depend on VcsBase
since all depend on functionality that this plugin offers. 继续示例,我们有Git
, SVN
等插件,它们都依赖于VcsBase
因为它们都依赖于该插件提供的功能。
I can look into these two variables but I have the feeling that there should be a better way than just sifting through the code of Qt Creator (not exactly beginner friendly). 我可以研究这两个变量,但我觉得应该有一种更好的方法,而不是仅筛选Qt Creator的代码(不完全适合初学者)。 I checked QPluginLoader but the only thing connected to the term dependent is platform-independent , which is not what I'm looking for. 我检查了QPluginLoader,但是与术语“ 依赖”相关的唯一东西是平台无关的 ,这不是我想要的。
The "trivial" way would be to check all available plugins and then - based on a predefined loading order - check if plugin A and B are available so that the present plugin C (which depends on both) can be loaded. “简单”的方法是检查所有可用的插件,然后-根据预定义的加载顺序-检查插件A和B是否可用,以便可以加载当前的插件C(取决于两者)。 However this would mean that I need to add the dependencies to the core application. 但是,这意味着我需要将依赖项添加到核心应用程序。 I do believe that this is something that each plugin needs to take care of on its own (more or less). 我确实相信这是每个插件都需要自己(或多或少)照顾的事情。
It seems that there is no direct way to do that. 似乎没有直接的方法可以做到这一点。 The only way I have found so far is through the JSON file that goes along with each plugin. 到目前为止,我发现的唯一方法是通过每个插件附带的JSON文件。 There one can enter a key - let's call it "deps" - and call the meta data through QPluginLoader::metaData()
. 在那里可以输入一个密钥-我们称之为“ deps”-并通过QPluginLoader::metaData()
调用元数据。 This function returns a QJsonObject
(the root of the JSON document. One can then find "deps" and get the content (for example a list of names of other plugins, that the current one depends on). Next one can check if the mentioned dependencies are present and loaded and so on. 此函数返回一个QJsonObject
(JSON文档的根。然后可以找到“ deps”并获取其内容(例如,当前插件所依赖的其他插件的名称列表)。下一个可以检查是否提到了该插件。存在和加载依赖项,依此类推。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.