简体   繁体   中英

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. 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 .

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). As an example there is the VcsBase (version control system base plugin):

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 . 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.

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). I checked QPluginLoader but the only thing connected to the term dependent is platform-independent , which is not what I'm looking for.

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. 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. There one can enter a key - let's call it "deps" - and call the meta data through 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM