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; see Section 9.5). This means that it 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, QTimer). QObject and types derived from QObject are not assignable. If you need to group objects of some non-assignable type, you can define a container of pointers, e.g., QList.

Категории