[Development] Lack of base classes/interfaces? Q*, Q*F

Thiago Macieira thiago.macieira at intel.com
Mon Apr 17 05:44:17 CEST 2017


Em domingo, 16 de abril de 2017, às 18:25:49 PDT, Jason H escreveu:
> I am wondering why all the Q* and Q*F classes (where $1 in [Rect, Point,
> etc]) don't use an interface? I recently moved some code from ints to
> floats, and I had to change far more code than I should have had to.

If you're thinking of a template class and make each of those just an 
instantiation of the template, it could be done, and yet wouldn't help you a 
lot. Each instantiation is a distinct type. Your code would need to be 
adapted.

It wouldn't be easy for us either, as the algorithms are subtly different. The 
rectangle and size, for example, store the inclusive bottom-right coordinate, 
whereas the floating point ones store them exclusive.

If you're thinking of base class with inheritance and virtuals, then you have 
to learn a lot about C++ efficiency. Those classes are too small for virtuals. 
It would be bad API design and an incredible overhead for little gain. As I 
mentioned, the classes have actually little in common between one another.

> My proposal is to change QRect to QRectI, and make QRect an interface.

That's a vague suggestion. Make a concrete proposal, please. Without virtuals, 
of course.

> I'm not fan of MS's Ieverything, but I think base classes/interfaces are
> under used in Qt. Why aren't there more of them?

You are thinking of classes with virtuals. QRect has no virtuals and shall 
never have them.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center




More information about the Development mailing list