abey
29th October 2009, 20:11
Hello all,
Please consider the following mock-up of how my application works:
class DataSource
{
public:
QVariant dataForKey(const QString &key);
};
class BaseWidget : public QWidget
{
Q_OBJECT
public:
BaseWidget(QWidget* parent);
void setDataSource(DataSource* ds) { this->ds = ds; }
virtual void draw(QPainter* painter) = 0;
protected:
DataSource* ds;
};
class SomeWidget : public BaseWidget
{
public:
virtual void draw(QPainter* painter)
{
// do some custom drawing using ds->dataForKey()
// with specific "key" parameter
}
};
My application has a repertoire of subclasses of BaseWidget that I would like to dynamically extend through plugins. Qt's documentation (http://doc.trolltech.com/4.5/plugins-howto.html) is quite clear on the basics, but covers only the case where the plugin can be implemented exclusively with pure Qt facilities. In this case, I would like the plug-in to be able to access my custom facilities, i.e. the DataSource mechanism in the mock-up above.
I'm not sure how to proceed toward the implementation of such a setup. How can I provide the plugins with access to facilities sitting in the main application? Should I put these facilities in a separate dynamic library against which both the application and the plugins will be linked? Or is there a potentially simpler way to achieve this?
Thanks in advance for your help,
Antoine
Please consider the following mock-up of how my application works:
class DataSource
{
public:
QVariant dataForKey(const QString &key);
};
class BaseWidget : public QWidget
{
Q_OBJECT
public:
BaseWidget(QWidget* parent);
void setDataSource(DataSource* ds) { this->ds = ds; }
virtual void draw(QPainter* painter) = 0;
protected:
DataSource* ds;
};
class SomeWidget : public BaseWidget
{
public:
virtual void draw(QPainter* painter)
{
// do some custom drawing using ds->dataForKey()
// with specific "key" parameter
}
};
My application has a repertoire of subclasses of BaseWidget that I would like to dynamically extend through plugins. Qt's documentation (http://doc.trolltech.com/4.5/plugins-howto.html) is quite clear on the basics, but covers only the case where the plugin can be implemented exclusively with pure Qt facilities. In this case, I would like the plug-in to be able to access my custom facilities, i.e. the DataSource mechanism in the mock-up above.
I'm not sure how to proceed toward the implementation of such a setup. How can I provide the plugins with access to facilities sitting in the main application? Should I put these facilities in a separate dynamic library against which both the application and the plugins will be linked? Or is there a potentially simpler way to achieve this?
Thanks in advance for your help,
Antoine