[Development] HEADS UP: Don't use QList, use Q_DECLARE_TYPEINFO

Smith Martin Martin.Smith at theqtcompany.com
Fri Jul 10 11:54:16 CEST 2015


Then I don't see why it is so inherently inefficient. The QList entry is allocated on the heap anyway. Doesn't QList<C> just allocate a bigger entry? And if I don't have the C object stored anywhere else, it has to be somewhere, so why not keep it in the QList entry?

martin 

________________________________________
From: development-bounces+martin.smith=theqtcompany.com at qt-project.org <development-bounces+martin.smith=theqtcompany.com at qt-project.org> on behalf of Giuseppe D'Angelo <giuseppe.dangelo at kdab.com>
Sent: Friday, July 10, 2015 11:12 AM
To: development at qt-project.org
Subject: Re: [Development] HEADS UP: Don't use QList, use Q_DECLARE_TYPEINFO

Il 10/07/2015 11:05, Curtis Mitch ha scritto:
> So QQuickItem, for example, should have Q_DECLARE_TYPEINFO?

No, because you can't put a QQuickItem in a container, since you can't
copy it. You can create a container of pointers to QQuickItems, but
pointers are automatically OK:

http://code.woboq.org/qt5/qtbase/src/corelib/global/qtypeinfo.h.html#79

> And please, whenever you add a new type (not just class, *any* type, incl.
> enums, but excluding QFlags (which are automatically primitive)),

^ and pointers.

> What happens if you don't use the macro for a type? Do containers assume the worst about that type (that it's complex, etc.)?

Yes, complex is the default. For QList, that means that every single
object it contains will be allocated on the heap with new.

HTH,
--
Giuseppe D'Angelo | giuseppe.dangelo at kdab.com | Software Engineer
KDAB (UK) Ltd., a KDAB Group company | Tel: UK +44-1625-809908
KDAB - The Qt Experts



More information about the Development mailing list