[Qt-interest] QObject based plugins

Andreas Pakulat apaku at gmx.de
Wed Aug 19 11:10:47 CEST 2009


On 19.08.09 10:55:18, Andre Somers wrote:
> In my application, I am using a lot of plugins. I am currently using 
> QPluginLoader and the Q_DECLARE_INTERFACE macro to define the interface. 
> However, I find the system a bit limited. While my plugins turn up as 
> QObjects and I can give them signals and slots, I can only do that in 
> the specific implementation. The interface itself is not a QObject.
> 
> I would really like to be able to create an interface complete with all 
> the wonderfull features Qt offers: signals, slots, introspection, etc. I 
> know I can cast the loaded plugins to QObject and connect to signals and 
> slots I know are (should be) there, but that is not a very nice way of 
> working. That means that the interface I define, is not really the 
> complete interface.
> 
> Is there some way to make the plugins right from the interface 
> definition real QObjects?

You could do that with one interface, but probably not all because....

> And does that also work if a plugin object implements more than one
> QObject-like interface?

This won't work. You cannot inherit multiply from QObject.

Now I don't know your plugin-loading-mechanism, but usually such mechanisms
have a base class in a shared library that all plugins subclass from and
then add the individual interfaces. Then the plugin-loading-mechanism just
returns this base class and you can then cast to the interface you want.

Also QPluginLoader already gives you a QObject when using a plugin via the
instance() method.

Andreas

-- 
You're almost as happy as you think you are.



More information about the Qt-interest-old mailing list