Hi

I am stuck while trying to implement an plugin-aware application. Mainly because I'm not sure it what I want to do is possible: I have a MDI area in my main window and I want to populate it with widgets obtained through a plugin interface. I've studied the plugin examples in the Qt documentation as well as the plugin interface described in "C++ GUI Programming with Qt" and they all differ from what I need because the plugins all return a object known to Qt, for example a QPixmap or a QPen or something like that. In my case, it needs to return a class that is defined by the creator of the plugin. I'll try to explain my problem in as much detail as possible, and there is probably an easy answer. Some code might make it clearer:

In my application, I have the following plugin interface:

Qt Code:
  1. class viewerInterface {
  2. public:
  3. virtual ~viewerInterface() { }
  4. virtual QStringList views() const = 0;
  5. virtual QWidget * loadViewer(const QString &view_type, QString dbTable, QString dbFile) = 0;
  6. };
  7. Q_DECLARE_INTERFACE(viewerInterface,"com.software_name.app_name.viewerInterface/0.1")
To copy to clipboard, switch view to plain text mode 

And an intended plugin for this interface is shown below:

Qt Code:
  1. class varMatrixReal : public QWidget, public Ui_varMatrixBase, public viewerInterface {
  2. Q_OBJECT
  3. Q_INTERFACES(viewerInterface)
  4. public:
  5. varMatrixReal(QWidget *parent = 0);
  6. void setupVUI(QString, QString); // Setup viewer user interface
  7. QStringList views() const;
  8. QWidget * loadViewer(const QString &view_type, QString dbTable, QString dbFile);
  9.  
  10. private slots:
  11. void Close();
  12. bool createDBConnection();
  13.  
  14. private:
  15. // Variables
  16. QSqlTableModel *dataModel;
  17. QSqlDatabase dbProject;
  18.  
  19. public:
  20. // Details received from application side
  21. QString dbTable;
  22. QString dbFilename;
  23.  
  24. };
  25.  
  26. #endif // !_VARMATRIXREAL_H_
To copy to clipboard, switch view to plain text mode 

where the classes it inherits from are the following:
QWidget - Needed since it will be a widget displayed in a MDI Area
Ui_varMatrixBase - GUI base class created with Qt designer
viewerInterface - The abstract interface base class

Now with this background the question is the following: When I want to use this plugin in my application, how is it possible to cast a pointer to the varMatrixReal class if the main application does not have any knowledge of the plugin except for the interface (or does it?).

The first step will be something like this:
Qt Code:
  1. QPluginLoader loader(pluginDir.absoluteFilePath(fileName));
  2. if (viewerInterface*interface = qobject_cast<viewerInterface*>(loader.instance()))
  3. interfaces.append(interface);
To copy to clipboard, switch view to plain text mode 

But after this, how is it possible to use the functions of the derived classes and not only the interface base class? I mean, to do this you should probably qobject_cast the interface pointer to a varMatrixReal class and add such an instance to the MDI Area, however how do I get the application to have knowledge of the varMatrixReal class? Or the more generic case where the plugin defined the needed derived class and the application does not have knowledge of this, in this case varMatrixReal.

I have the feeling it should be possible because the plugin is a library which contains the class definition in any case. Do I only need to link to it in the .pro file perhaps?

Thanks in advance, I hope the question is clear enough.
Jaco