[Qt-creator] Invoke a method from plugin

Ziller Eike Eike.Ziller at theqtcompany.com
Mon Aug 10 08:54:47 CEST 2015


> On Aug 7, 2015, at 5:39 PM, Andrey Poltavets <andrey.poltavets at gmail.com> wrote:
> 
> Not sure what you mean with that.
> I misled you. I mean in my app I've launched instance of QtC's PluginManager and load my plugin to it. Now I need to investigate how can I use API of my plugin by PluginManager instance.

So, if I understand you correctly, you have an application, and want to make it possible to extend your application by plugins, and try to use Qt Creator’s plugin manager for that?
But then I do not know what you mean with "I don't thinks so, because there are only few plugins with macro Q_INVOKABLE in QtC's sources.”

Several possibilities for that case though. Usually your application would provide exported API for plugins, and plugins link against a corresponding library from the app and use that.

E.g.
-----
App provides mehtods that can be used by plugins:
class APP_EXPORT MyAppPluginAPI {
public:
    static void doSomethingInApplication();
};
Plugin calls MyAppPluginAPI::doSomethingInApplication() at some point.
-----
App provides an interface that plugins can implement:
class APP_EXPORT SomeInterface {
public:
    static void registerSomeInterface(SomeInterface *impl);

    virtual void doSomething() = 0;
    virtual RetValue getSomething() = 0;
};
Plugins implement that interface, and in e.g. IPlugin::initialize do
SomeInterface::registerSomeInterface(new MyPluginsSomeInterfaceImpl);
-----
Or the same, but using the plugin manager object pool (<-- possible performance issues there!)
App provides an interface that plugins can implement:
class APP_EXPORT SomeInterface : public QObject {
public:
    virtual void doSomething() = 0;
    virtual RetValue getSomething() = 0;
};
Plugins implement that interface, and put an instance in the object pool in IPlugin::initialize
addAutoreleasedObject(new MyPluginsSomeInterfaceImpl);
The app gets the implementations and does something on them some time after loading plugins
foreach (SomeInterface *impl, PluginManager::getObjects<SomeInterface>()) impl->doSomething();
Here you can avoid the link dependency on your plugin by using Q_DECLARE_INTERFACE
-----
The app provides specialized plugin interfaces
class APP_EXPORT SpecializedPluginInterface : public ExtensionSystem::IPlugin {
public:
[....]
    virtual void doSomething() = 0;
    virtual RetValue getSomething() = 0;
};
Plugins can be of that type instead of just IPlugin, and the application calls methods on them with something like
foreach (PluginSpec *spec, PluginManager::plugins())
    if (auto specialPlugin = qobject_cast<SpecializedPluginInterface *>(spec->plugin()))
        specialPlugin->doSomething();
-----
ES::invoke is also possible, but error prone.

Br, Eike

> 2015-08-07 17:19 GMT+03:00 Ziller Eike <Eike.Ziller at theqtcompany.com>:
> 
> > On Aug 7, 2015, at 1:17 PM, Andrey Poltavets <andrey.poltavets at gmail.com> wrote:
> >
> > Hello.
> > How to invoke method from plugin?
> > I have two suggestions:
> > 1) function ExtensionSystem::invoke ? I don't thinks so, because there are only few plugins with macro Q_INVOKABLE in QtC's sources.
> > 2) public slot PluginManager::remoteArguments ?
> 
> 
> 
> > I already have launched and loaded my plugin in insular instance of PluginManager.
> 
> Not sure what you mean with that.
> 
> > Now I need to investigate how to invoke a method. Please don't open all the cards for my fun, just give me a hint. :)
> 
> Make your plugin depend on the other plugin (QTC_PLUGIN_DEPENDS) and use that plugin’s API directly.
> 
> Br, Eike
> 
> --
> Eike Ziller, Senior Software Engineer - The Qt Company GmbH
> 
> The Qt Company GmbH, Rudower Chaussee 13, D-12489 Berlin
> Geschäftsführer: Mika Pälsi, Juha Varelius, Tuula Haataja
> Sitz der Gesellschaft: Berlin, Registergericht: Amtsgericht Charlottenburg, HRB 144331 B
> 
> 
> 
> 
> -- 
> Respectfully, 
> Andrey Poltavets

-- 
Eike Ziller, Senior Software Engineer - The Qt Company GmbH
 
The Qt Company GmbH, Rudower Chaussee 13, D-12489 Berlin
Geschäftsführer: Mika Pälsi, Juha Varelius, Tuula Haataja
Sitz der Gesellschaft: Berlin, Registergericht: Amtsgericht Charlottenburg, HRB 144331 B



More information about the Qt-creator mailing list