PDA

View Full Version : Is it possible to create a plugin interface that uses inheritance?



themolecule
21st August 2007, 04:05
if I have a plugin interface that inherits from another class, how do I get plugins compiled with the interface to link (LIB) to the inherited class?

I want to have something like

class AInterface : public B
{
virtual ~AInterface() {}
}

Q_DECLARE_INTERFACE(AInterface, "blah")

which compiles fine but won't load, seems to have silent linker errors in QPluginLoader with class B.

QCasper
21st August 2007, 07:06
I think that is not good idea to inherit interface from a concrete class. You probably should to revise your architecture.

wysota
21st August 2007, 08:26
Just make B inherit the interface, not the other way round.

fullmetalcoder
21st August 2007, 10:13
Plugins can't access members/methods of a class that is defined in the application that load them. If B was a Qt class (and not extended in any way within your app) you could use that inheritance scheme. Otherwise you have two solutions left : drop it and use a new design or put the B class ( and it's dependencies) into a shared library that will be accessible to both the application and the plugins since both could link to it...

themolecule
21st August 2007, 14:12
If I was to create a shared library, I'm guessing it would make sense for both the application and the plugin to link to the shared dylib instead of the app compiling it in and the plugin linking.

Would I create a dylib by using the TEMPLATE=lib (with CONFIG=?something?) method or is there another way?

fullmetalcoder
22nd August 2007, 07:46
Would I create a dylib by using the TEMPLATE=lib (with CONFIG=?something?) method or is there another way?
That's the way. Add "shared" and/or "dll" to the CONFIG var to make sur you don't get a static build...

themolecule
22nd August 2007, 13:50
Thanks!

And I'm guessing that in the app and the plugin, I include the header for my shared library and include the dylib in the LIBS .pro setting (not include the source cpp in either). This has nothing to do with QPluginLoader and I will have to use otool and install_name_tool to move things for deployment. Is that right?

fullmetalcoder
23rd August 2007, 12:33
And I'm guessing that in the app and the plugin, I include the header for my shared library and include the dylib in the LIBS .pro setting (not include the source cpp in either). This has nothing to do with QPluginLoader and I will have to use otool and install_name_tool to move things for deployment. Is that right?
That's right (though I can't help you with Mac deployment issues...). You may also need to change your INCLUDEPATH acordingly.