PDA

View Full Version : QWidget-derived Application Plugins



SnarlCat
14th March 2008, 16:37
All-

I'm building an application that I'd like to have load a set of self-contained modules (compiled as Libraries and loaded through the QPluginLoader framework). Each module inheirits from QWidget and implements a custom interface of my design.

I've been successful in building such a module and having it loaded (proof-positive in that I can call functions in the library module from the application and get correct values back).

The plugin examples packaged with Qt provide hints at nearly everything I need to do, except one thing -- these modules contain UI's that need to be drawn, and at present are not.

The usual process, it seems, is to setup the interface in the constructor, having passed a parent widget to draw upon. In the plugin framework, the constructor is called with the call to QPluginLoader::loader(QString path). This does not seem to provide the means to say 'this is a graphical component -- draw it on this surface".

So -- after much introduction the question: How do I get a stand-alone QWidget-drived library plugin to draw its' components on a specified surface?

Thanks for your help!

SnarlCat

jpn
18th March 2008, 13:56
Instead of making the plugin itself a QWidget, make it allocate and return a QWidget when requested, more or less like this:


class MyPluginInterface
{
...
QWidget* createWidget(QWidget* parent) = 0;
...
};

SnarlCat
25th March 2008, 18:25
With some retooling, it worked!

Thank you.

I'd discovered a similar (though more convoluted) way just before reading your post, but your suggestion is, IMO, better than mine...

Follow-on question:

These modules are an aggregation of widgets and code, connected through module-private signals and slots. Now that the UI is drawn on a parent object, how I do re-connect these private signals and slots so that the interface is processed properly? I might have thought they would be reconnected as they're part of the same block of code, but they don't seem to be.. Thoughts?

Thanks!

SnarlCat