PDA

View Full Version : qt signal in a Plugin base class



trallallero
17th November 2011, 14:58
I have created a GUI with a plugin system.
There's a PluginInterface abstract class:



class PluginInterface
{
virtual methods ...
}


A plugin has a class like this:



class TextValidatorPlugin : public QObject, public PluginInterface
{
Q_OBJECT
Q_INTERFACES(DB_PluginSystem::PluginInterface)
...

signals:
void PluginSaveSignal(const QString& pluginName, const QString& config);
}


Now the problem is in the loader:




QPluginLoader loader(m_PluginsDir.absoluteFilePath(fileName));

QObject *plugin = loader.instance();
if (plugin)
{
PluginInterface* pi = qobject_cast<PluginInterface*>(plugin);
if (pi)
{
pi->SetParent(m_Parent);
pi->SetMenu (pluginMenu);
...
connect(pi , SIGNAL(PluginSaveSignal(const QString&, const QString&)),
this, SLOT (PluginSaveSlot (const QString&, const QString&)));


The connect of course fails because the plugin loader knows only the base class (the interface) and not the class of the plugin.
But I cannot put the signal in the base class as it's not inherited from QObject.
And I cannot derive the plugin base class from QObject because the plugin classes (those derived from the plugin base class) already inherit from QObject...

is there as solution for this ?

Added after 11 minutes:

Ok, solved by my self.
Stupid me, I don't have to use PluginInterface* pi pointer but the QObject* plugin one in the connect.

Added after 1 39 minutes:

But there's still a problem:

The plugin loader assumes that all the plugins have a signal

void PluginSaveSignal(const QString&, const QString&)
but I cannot force who writes the plugins to implement it.

I know it sounds weird, but is it possible somehow to create a signal pure virtual ?
Like a:

void PluginSaveSignal(const QString&, const QString&) = 0;