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

Thiago Macieira thiago.macieira at intel.com
Tue Jul 21 17:47:28 CEST 2015


On Tuesday 21 July 2015 10:19:59 Matthew Woehlke wrote:
> On 2015-07-21 01:06, Thiago Macieira wrote:
> > On Tuesday 21 July 2015 02:26:41 Kevin Kofler wrote:
> >> For the implicitly shared data types, QList actually does NOT add another
> >> layer of indirection (as documented: "If T is itself a pointer type or a
> >> basic type that is no larger than a pointer, or if T is one of Qt's
> >> shared
> >> classes, then QList<T> stores the items directly in the pointer array."),
> >> so  in that case, it is almost the same as QVector, except that it allows
> >> prepending items much more efficiently (O(1) in many cases, whereas it's
> >> always O(n) in QVector).
> > 
> > Except if the type is larger than sizeof(void*), like QVariant is.
> > 
> > Or like QString and QByteArray will be in Qt 6.
> 
> Are these still implicitly shared? 

Yes, in large mode. In small string/array mode, they wouldn't share, of 
course.

> Is it possible to have Qt type traits
> on a type T such that QList<T> will always be QVector-like? Or would it
> be impossible to support that in QList? (This would be for Qt 6, obviously.)

We could create a user-configurable trait, but experience in the past 10 years 
has shown that people do not use the macros that make things efficient. So we 
can't depend on the right actions to make things efficient.

Just look at how many commits Marc has needed to do in Qt itself to declare 
types as movable.

> It seems like it would be useful for any shared-data class to be
> QVector-like in QList, even if larger than a single pointer. (At least,
> have the ability to make such a type thusly.)
> 
> 
> ...Is QStringList going to become a QVector<QString>?

Both issues need first that we decide whether QList and QVector will be the 
same or not.

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




More information about the Development mailing list