I have created a GUI with a plugin system.
There's a PluginInterface abstract class:
class PluginInterface
{
virtual methods ...
}
class PluginInterface
{
virtual methods ...
}
To copy to clipboard, switch view to plain text mode
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);
}
class TextValidatorPlugin : public QObject, public PluginInterface
{
Q_OBJECT
Q_INTERFACES(DB_PluginSystem::PluginInterface)
...
signals:
void PluginSaveSignal(const QString& pluginName, const QString& config);
}
To copy to clipboard, switch view to plain text mode
Now the problem is in the loader:
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&)));
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&)));
To copy to clipboard, switch view to plain text mode
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&)
void PluginSaveSignal(const QString&, const QString&)
To copy to clipboard, switch view to plain text mode
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;
void PluginSaveSignal(const QString&, const QString&) = 0;
To copy to clipboard, switch view to plain text mode
Bookmarks