PDA

View Full Version : plugin accessing data from qApp



itpenguin
27th July 2016, 15:43
Plugins are normally made for accessing plugin methods in the main program.

Now I have an application, where the plugin needs to call a method from the main program.
How is this done?
I have a working solution using QMetaObject::invoke(),, but using this is rather complex.

Is there an easier way to call an application method from within the plugin?

anda_skoa
27th July 2016, 16:57
You can always specify a host API and give an object implementing that API to the plugin object.

E.g.


class HostApi
{
public:
virtual void doSomething() = 0;
};

The plugin API would then simply need something like


class Plugin
{
public:
virtual void setHost(HostApi *host) = 0;
};

The host application can implement the API in any object it likes, it could even hand each plugin a different instance of the implementation or even different implementations.

Cheers,
_

itpenguin
28th July 2016, 09:19
OK, my mistake was the declaration of doSomething(). It must be virtual, because the address of the method is allocated dynamically at run time.