[Qt-interest] inteface implementation in C++/Qt
Daniel Pecar
daniel.pecar at hacon.de
Wed Feb 23 12:33:07 CET 2011
Am 23.02.2011 12:16, schrieb Konstantin Tokarev:
>
> 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"
>
>
[1] Or Java-like: "Abstract Class".
Grüße,
Daniel
--
Dipl.-Inf. Daniel Pecar
Entwicklung Planungs-/ Dispositionssysteme
HaCon Ingenieurgesellschaft mbH
Lister Str. 15
30163 Hannover
Germany/Deutschland
Tel. +49 511 33699-485
Fax. +49 511 33699-99
mailto:daniel.pecar at hacon.de
http://www.hacon.de
Registry Court/Amtsgericht Hannover HRB 1712
Managing Directors/Geschäftsführer: Michael Frankenberg,
Dr.-Ing. Marian Gaidzik, Dr.-Ing. Werner Kretschmer,
Werner Sommerfeld, Dr.-Ing. Volker Sustrate, Peter Talke
More information about the Qt-interest-old
mailing list