I don't really see a problem in doing this the way I said
I made a few plugins in my life (both using and not using the Qt plugin framework) and they always worked as expected in the form I suggested. COM seems to work too, Java implementing interfaces seems to work, other languages as well... I don't really see a problem in creating an implementation of an interface that returns an instance of implementation of another interface...
I think it should look more or less like so:
struct MyInterface {
virtual void method1() = 0;
virtual void method2() const = 0;
virtual int method3() = 0;
virtual double method4(int) = 0;
virtual ~MyInterface(){}
};
struct PluginInterface {
virtual ~PluginInterface(){}
virtual MyInterface
*create
(QWidget *parent
=0) = 0;
};
Q_DECLARE_INTERFACE(PluginInterface, "xxx")
struct MyInterface {
virtual void method1() = 0;
virtual void method2() const = 0;
virtual int method3() = 0;
virtual double method4(int) = 0;
virtual ~MyInterface(){}
};
struct PluginInterface {
virtual ~PluginInterface(){}
virtual MyInterface *create(QWidget *parent=0) = 0;
};
Q_DECLARE_INTERFACE(PluginInterface, "xxx")
To copy to clipboard, switch view to plain text mode
And implementation:
struct MyInterfaceImpl
: public QObject,
public MyInterface
{ void method1(){ printf("BLABLA\n"); }
void method2() const { printf("BLABLA\n"); }
int method3() { return 7; }
double method4(int a) { return a*1.0/7.0; }
~MyInterfaceImpl(){}
};
struct Plugin
: public QObject,
public PluginInterface
{ Q_OBJECT
Q_INTERFACES(PluginInterface)
~Plugin(){}
MyInterface
*create
(QWidget *parent
=0){ return new MyInterfaceImpl
(parent
);
}};
struct MyInterfaceImpl : public QObject, public MyInterface {
MyInterfaceImpl(QWidget *parent = 0) : QObject((QObject*)parent){}
void method1(){ printf("BLABLA\n"); }
void method2() const { printf("BLABLA\n"); }
int method3() { return 7; }
double method4(int a) { return a*1.0/7.0; }
~MyInterfaceImpl(){}
};
struct Plugin : public QObject, public PluginInterface {
Q_OBJECT
Q_INTERFACES(PluginInterface)
Plugin(QObject *parent=0) : QObject(parent){}
~Plugin(){}
MyInterface *create(QWidget *parent=0){ return new MyInterfaceImpl(parent); }
};
To copy to clipboard, switch view to plain text mode
Bookmarks