PDA

View Full Version : QtPlugins how to communicate between plugins?



BeS
17th December 2008, 11:53
Hello,

i'm working on a program which has a QMdiArea. The QMdiSubWindows are QPlugins which can be loaded during runtime.

This is the current plugin Interface:



#ifndef INTERFACE_H
#define INTERFACE_H

#include <QtPlugin>

class PluginInterface
{
public:
virtual ~PluginInterface() { }

virtual QString getName() = 0;
virtual QWidget* getWidget() = 0;

};

Q_DECLARE_INTERFACE(PluginInterface, "foo.demo.PluginInterface/1.0")

#endif


in getWidget() i load or create a widget and than the main program can get the widget with getWidget() and put it into a QMdiSubWindow.

So far it works quite well.

But now i want to have some communication between the plugins. E.g. if i press a button in one plugin something should happen in the other plugin.

I have tried to give the plugins a reference to their communication partner when i load a plugin. But it doesn't work. I think the problem was that i always casted the plugins down to qwidget and than within the plugin again up to foobar-plugin but than of course all the special foobar-plugin methods are lost due the "down-cast". But the main program doesn't know about all possible plugin classes. So i'm stuck and don't know how to solve the problem.

Can you give me some hints how i could achieve this?

Thanks!

caduel
17th December 2008, 11:59
Give the central class (the mdi window, perhaps) a method getPlugin(QString) or so.
Have that method return the pointer to the plugins common base class (or NULL, if the plugin/window is not present).
Cast that pointer at the calling plugin to the required type of the other plugin. Then just call the regular method.
That way the plugins know about each other... but, if you want to call methods, they obviously can't be completely independent, so that probably is ok.

HTH