10.2.  Containers

[ fromfile: generics.xml id: containers ]

Qt's container classes are used to collect value types (things that can be copied), including pointers to object types (but not object types themselves). Qt containers are defined as template classes which leave the collected type unspecified. Each data structure is optimized for different kinds of operations. In Qt 4 there are several template container classes to choose from.

A type parameter T for a template container class or key type for an associative container must be an assignable data type (i.e., a value type). (Section 9.5). This means that the T must have a public default constructor, copy constructor, and assignment operator.

Basic types (e.g, int, double, char, etc.) and pointers are assignable. Some Qt types are assignable (e.g., QString, QDate, QTime). QObject and types derived from QObject, however, are not assignable. If you need collect objects of some non-assignable type, you can define a container of pointers, e.g., QList<QFile*>.