6.8.  Containers

[ fromfile: inheritance-intro.xml id: containers ]

Qt's container classes collect value types (things that can be copied), including pointers to object types[49] (but not object types themselves). Qt containers are defined as template classes that leave the collected type unspecified. Each data structure is optimized for different kinds of operations. In Qt 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 8.1). This means that 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 to collect objects of some nonassignable type, you can define a container of pointers, e.g., QList<QFile*>.



[49] Chapter 8 discusses QObject and object types.