[Qt-interest] Basic question on applying QObject principles toInterfaces
Mandeep Sandhu
mandeepsandhu.chd at gmail.com
Wed May 5 07:43:19 CEST 2010
> Can be changed into:
>
> class MyInterface
> {
> public:
> virtual ~MyInterface() {} = 0;
> virtual const QObject* object() const = 0;
> virtual void someMethod() = 0;
> virtual void mySignal() = 0; // optional
> };
>
>> class MyInterfaceImpl : public MyInterface
>> {
>> Q_OBJECT
>> public:
>> MyInterfaceImpl() {}
>> ~MyInterfaceImpl() {}
>>
>> void someMethod() {
>> // do something
>> emit mySignal();
>> }
>> signals:
>> void mySignal();
>> }
>
> Can be changed into:
>
> class MyInterfaceImpl : public QObject, public MyInterface
> {
> Q_OBJECT
> public:
> MyInterfaceImpl() {};
> ~MyInterfaceImpl() {};
> const QObject* object() const { return this; };
> void someMethod() { emit mySignal(); };
> signals:
> void mySignal();
> };
>
> With this scenario you could also pass in a parent QObject*:
>
> MyInterfaceImpl(QObject* parent) : QObject(parent) {};
>
> Connects should be done using MyInterface::object() instead of MyInterface.
Hmmm....interesting solution Ben.
This does make the interface class "pure", albeit at the cost of a
little confusion to the user who would think of mySignal() as a normal
function that can be called.
Though this is not a big deal and one can always comment the interface
def nicely! :)).
Thanks,
-mandeep
>
> Hope it helps.
> Greets,
>
>
> Ben
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
More information about the Qt-interest-old
mailing list