[Qt-interest] inteface implementation in C++/Qt
Konstantin Tokarev
annulen at yandex.ru
Wed Feb 23 12:16:32 CET 2011
23.02.2011, 05:21, "Sean Hayes" <sean.t.hayes at vanderbilt.edu>:
>> Under a language like ObjectiveC I would define an Interface and simply state that the class implements the interface. Is there an appropriate C++ or Qt way of doing this?
>
> The C++ way to do this would be to create a class that contains only pure virtual functions and use that as your interface. Then use multiple inheritance to implement the interface (which is safe because all theinterface functions are pure virtual). However, this is somewhat limiting because your interface cannot inherit any Qt classes and therefore cannot contain signal or slot declarations.
It's not mandatory to make all methods pure virtual: if their names don't collide with names of non-private methods already present in your other base class (e.g., QWidget), you can safely provide implementations for methods of your "interface"[1]
You can also have data memebrs in your "interface", if their names don't collide with non-private members of QWidget
You cvan also try to use virtual inheritance (virtually inherit your "interface" and classes of MDI windows from QWidget), but I have not tested if it works.
[1] It's not correct to call it "interface" anymore, probably the better name is "mixin"
--
Regards,
Konstantin
More information about the Qt-interest-old
mailing list