Описание тега qlist
QList is a class in Qt that implements a list, providing fast index-access, as well as fast insertions and removals of elements.
QList
is a template class which provides lists.
The QList
itself is represented as an array of pointers to its elements. However, one must remember that if the element is a pointer itself, or if the element is smaller or equal to a standard pointer, or if the element is one of the Qt's shared classes, the QList
will hold the element itself instead of a pointer to it.
An example of using a QList
will look like this:
// adding items with overloaded << operator
QList< QString > myList;
myList << "Hello world!" << "This is a QList example" << "It's very easy to use.";
// accessing elements by index (use .at() for read-only access)
if( myList.at(0) == "Hello world!" )
{
// modify elements by index (use subscript)
myList[0] = "Goodbye world!";
}
// accessing elements with an iterator
QList< QString >::iterator it = myList.begin();
while( it != myList.end() )
{
// do stuff
}
The official Qt documentation can be found here for Qt 4.8 and here for Qt 5.