Hi:
The application I'm trying to develop must be extended using plugins. I have a XML file similar to this (I omitted some non important parts):
<program>
<component type="plugin1"/>
<component type="plugin2"/>
<component type="plugin1"/>
<component type="plugin3"/>
</program>
So, for each <component> element that I read I create a new page on a QStackedWidget containing a custom widget defined by the classes Plugin1, Plugin2 and Plugin3. Is very easy when I know the names of all the plugins because I can do something like:
class AbstractPlugin
: public QObject{ //...
};
//all these classes implements "widget()"
class Plugin1 : public AbstractPlugin{/*...*/};
class Plugin2 : public AbstractPlugin{/*...*/};
class Plugin3 : public AbstractPlugin{/*...*/};
QList<AbstractPlugin* > components
QString type
//this value was readed from the XML in some moment
if(type == "Plugin1")
components.append(new Plugin1());
else if(type == "Plugin2")
components.append(new Plugin2());
else if(type == "Plugin3")
components.append(new Plugin3());
foreach(AbstractPlugin* c, components){
stackedWidget->addPage(c->widget());
}
class AbstractPlugin : public QObject{
//...
virtual QWidget* widget() = 0;
};
//all these classes implements "widget()"
class Plugin1 : public AbstractPlugin{/*...*/};
class Plugin2 : public AbstractPlugin{/*...*/};
class Plugin3 : public AbstractPlugin{/*...*/};
QList<AbstractPlugin* > components
QString type //this value was readed from the XML in some moment
if(type == "Plugin1")
components.append(new Plugin1());
else if(type == "Plugin2")
components.append(new Plugin2());
else if(type == "Plugin3")
components.append(new Plugin3());
foreach(AbstractPlugin* c, components){
stackedWidget->addPage(c->widget());
}
To copy to clipboard, switch view to plain text mode
But, if I dont know the names of all the plugins because I don't write each one, how can I specify the correct constructor to call?
Bookmarks