Monday, January 20, 2014

Extending plugins - a peculiar case

Link to Code Archive

I hit upon a very weird scenario recently and found out that there was no easy way to get the plugin working for this scenario.

So after searching a while for the possible solution and understanding that the solution would be indeed difficult to implement, I stumbled upon a post that gave me the solution. 

The scenario first: consider that there's some functionality in the Plugin container that you want to access from within the plugin. Lets consider a main thread ( GUI thread) refresh function that updates some part of GUI which the plugin provides the data for. And we want to call this refresh from plugin after certain operations in plugin are completed. Lets say that the plugin updates some values and that need updating the main GUI.
So we have seen how interface objects let us access plugin functionality and by creative use of base class pointers and container calls how we can access objects and functionality in the plugin. So here we are going to be more creative and call main GUI functionality from plugin. 

Below we get a QDialog from the plugin and add it to main window.

The formula is same. In qt the signals themselves are just functions or at least appear as functions. So we are declaring the signal in the plugin as another function. While in main class I. E. Our plugin container, we will use a dynamic cast of the interface object itself to QObject from which we will receive the signal.

Here is the connect function code that does this magic. 

In plugin we declare this signal as any other signal. And use it just so. Its not a straight forward way to do things but it works!

No comments:

Post a Comment