[Qt-interest] QObject based plugins
michael.goddard at nokia.com
michael.goddard at nokia.com
Fri Aug 21 07:14:49 CEST 2009
> Let me rephrase my question then:
> I have a series of interfaces that plugins can implement.
> There is one
> main, basic interface, and a series of smaller, secundairy interfaces
> that the plugins can *additionally* implement. These interfaces are
> defined in a header that is included from the main codebase by the
> plugins. I am using QPluginLoader::instance() and the
> Q_DECLARE_INTERFACE and Q_INTERFACES macro's to define and load the
> plugins.
> Is there some way to make my primairy interface QObject derived, so I
> can define the needed signals and slots in the interface?
Perhaps not the exact answer, but another way to do this is to have your plugin interface just be a factory interface for your actual QObject derived classes.
E.g.:
class MyPlugin : public Qobject
{
Q_OBJECT
public slots:
void doSomething(MyOtherObject* bar);
signals:
void didSomething(int baz);
};
class MyPluginFactory
{
virtual ~MyPluginFactory() {}
virtual MyPlugin* MyPluginInterface() const = 0;
};
Q_DECLARE_INTERFACE(MyPluginFactory, "my plugin factory");
For the multiple interface inheritance part of things, well.. That won't work if each interface needs to be a QObject for the signals and slots, but you might be able to have multiple interface functions in the "factory". Internally those objects would probably share state somehow. It is a bit messy :/
E.g.
class MyInterface1 : public QObject {}
class MyInterface2 : public QObject {}
class MyInterface3 : public QObject {}
class MyPluginWrapper
{
virtual ~MyPluginWrapper() {}
virtual MyInterface1* interface1() const = 0;
virtual MyInterface2* interface2() const = 0;
virtual MyInterface3* interface3() const = 0;
}
Q_DECLARE_INTERFACE(MyPluginWrapper, "My Plugin Wrapper");
I'm sure you could come up with a scheme somewhat like COM this way :)
Cheers,
MichaelG
--
Qt Developer Days 2009 | Registration Now Open!
Munich, Germany: Oct 12 - 14
San Francisco, California: Nov 2 - 4
http://qt.nokia.com/qtdevdays2009
More information about the Qt-interest-old
mailing list