QLinkedList Class ReferenceThe QLinkedList class is a template class that provides linked lists. Далее... #include <QLinkedList> Inherited by: Q3ValueList. Замечание: Все функции в этом классе реентерабельны. Открытые типы
Открытые функции
Статические открытые члены
Связанные нечлены класса
Подробное описаниеThe QLinkedList class is a template class that provides linked lists. QLinkedList<T> is one of Qt's generic container classes. It stores a list of values and provides iterator-based access as well as constant time insertions and removals. QList<T>, QLinkedList<T>, and QVector<T> provide similar functionality. Вот краткий обзор:
Here's an example of a QLinkedList that stores integers and a QLinkedList that stores QTime values: QLinkedList<int> integerList; QLinkedList<QTime> timeList; QLinkedList stores a list of items. The default constructor creates an empty list. To insert items into the list, you can use operator<<(): QLinkedList<QString> list; list << "one" << "two" << "three"; // list: ["one", "two", "three"] If you want to get the first or last item in a linked list, use first() or last(). If you want to remove an item from either end of the list, use removeFirst() or removeLast(). If you want to remove all occurrences of a given value in the list, use removeAll(). A common requirement is to remove the first or last item in the list and do something with it. For this, QLinkedList provides takeFirst() and takeLast(). Here's a loop that removes the items from a list one at a time and calls delete on them: QLinkedList<QWidget *> list; ... while (!list.isEmpty()) delete list.takeFirst(); QLinkedList's value type must be an assignable data type. Это охватывает большинство обычно используемых типов данных, но компилятор не позволит вам хранить как значение, например, QWidget; вместо этого сохраняйте QWidget *. A few functions have additional requirements; for example, contains() and removeAll() expect the value type to support operator==(). Эти требования отражены в описании функций. If you want to insert, modify, or remove items in the middle of the list, you must use an iterator. QLinkedList provides both Java-style iterators (QLinkedListIterator and QMutableLinkedListIterator) and STL-style iterators (QLinkedList::const_iterator and QLinkedList::iterator). See the documentation for these classes for details. See also QLinkedListIterator, QMutableLinkedListIterator, QList, and QVector. Описание типов-членовtypedef QLinkedList::ConstIteratorQt-style synonym for QLinkedList::const_iterator. typedef QLinkedList::IteratorQt-style synonym for QLinkedList::iterator. typedef QLinkedList::const_pointerПсевдоним типа для const T *. Предоставлен для совместимости с STL. typedef QLinkedList::const_referenceTypedef for const T &. Предоставлен для совместимости с STL. typedef QLinkedList::difference_typeПсевдоним типа для ptrdiff_t. Предоставлен для совместимости с STL. typedef QLinkedList::pointerПсевдоним типа для T *. Предоставлен для совместимости с STL. typedef QLinkedList::referenceПсевдоним типа для T &. Предоставлен для совместимости с STL. typedef QLinkedList::size_typeПсевдоним типа для int. Предоставлен для совместимости с STL. typedef QLinkedList::value_typeПсевдоним типа для T. Предоставлен для совместимости с STL. Описание функций-членовQLinkedList::QLinkedList ()Constructs an empty list. QLinkedList::QLinkedList ( const QLinkedList<T> & other )Создаёт копию other. This operation occurs in constant time, because QLinkedList is implicitly shared. This makes returning a QLinkedList from a function very fast. If a shared instance is modified, it will be copied (copy-on-write), and this takes linear time. Смотрите также operator=(). QLinkedList::~QLinkedList ()Destroys the list. References to the values in the list, and all iterators over this list, become invalid. void QLinkedList::append ( const T & value )Inserts value at the end of the list. Пример: QLinkedList<QString> list; list.append("one"); list.append("two"); list.append("three"); // list: ["one", "two", "three"] This is the same as list.insert(end(), value). Смотрите также operator<<(), prepend() и insert(). T & QLinkedList::back ()Эта функция обеспечивает совместимость с STL. Это эквивалентно last(). const T & QLinkedList::back () constЭто перегруженная функция. iterator QLinkedList::begin ()Returns an STL-style iterator pointing to the first item in the list. Смотрите также constBegin() и end(). const_iterator QLinkedList::begin () constЭто перегруженная функция. void QLinkedList::clear ()Removes all the items in the list. See also removeAll(). const_iterator QLinkedList::constBegin () constReturns a const STL-style iterator pointing to the first item in the list. Смотрите также begin() и constEnd(). const_iterator QLinkedList::constEnd () constВозвращает константный итератор в стиле STL, указывающий на воображаемый элемент после последнего элемента в списке. Смотрите также constBegin() и end(). bool QLinkedList::contains ( const T & value ) constReturns true if the list contains an occurrence of value; otherwise returns false. Эта функция требует, чтобы у типа значения существовала реализация operator==(). See also QLinkedListIterator::findNext() and QLinkedListIterator::findPrevious(). int QLinkedList::count ( const T & value ) constReturns the number of occurrences of value in the list. Эта функция требует, чтобы у типа значения существовала реализация operator==(). Смотрите также contains(). int QLinkedList::count () constТо же, что и size(). bool QLinkedList::empty () constЭта функция обеспечивает совместимость с STL. It is equivalent to isEmpty() and returns true if the list is empty. iterator QLinkedList::end ()Returns an STL-style iterator pointing to the imaginary item after the last item in the list. Смотрите также begin() и constEnd(). const_iterator QLinkedList::end () constЭто перегруженная функция. bool QLinkedList::endsWith ( const T & value ) constReturns true if the list is not empty and its last item is equal to value; otherwise returns false. Эта функция была введена в Qt 4.5. Смотрите также isEmpty() и last(). iterator QLinkedList::erase ( iterator pos )Removes the item pointed to by the iterator pos from the list, and returns an iterator to the next item in the list (which may be end()). Смотрите также insert(). iterator QLinkedList::erase ( iterator begin, iterator end )Это перегруженная функция. Удаляет все элементы с begin до (но не включая) end. T & QLinkedList::first ()Returns a reference to the first item in the list. This function assumes that the list isn't empty. Смотрите также last() и isEmpty(). const T & QLinkedList::first () constЭто перегруженная функция. QLinkedList<T> QLinkedList::fromStdList ( const std::list<T> & list ) [static]Returns a QLinkedList object with the data contained in list. The order of the elements in the QLinkedList is the same as in list. Пример: std::list<double> stdlist; list.push_back(1.2); list.push_back(0.5); list.push_back(3.14); QLinkedList<double> list = QLinkedList<double>::fromStdList(stdlist); Эта функция была введена в Qt 4.1. See also toStdList(). T & QLinkedList::front ()Эта функция обеспечивает совместимость с STL. Это эквивалентно first(). const T & QLinkedList::front () constЭто перегруженная функция. iterator QLinkedList::insert ( iterator before, const T & value )Вставляет значение value перед элементом, на который указывает итератор before. Возвращает итератор, указывающий на вставленное значение. See also erase(). bool QLinkedList::isEmpty () constВозвращает true, если список не содержит элементов; в противном случае возвращается false. Смотрите также size(). T & QLinkedList::last ()Returns a reference to the last item in the list. This function assumes that the list isn't empty. Смотрите также first() и isEmpty(). const T & QLinkedList::last () constЭто перегруженная функция. void QLinkedList::pop_back ()Эта функция обеспечивает совместимость с STL. It is equivalent to removeLast(). void QLinkedList::pop_front ()Эта функция обеспечивает совместимость с STL. It is equivalent to removeFirst(). void QLinkedList::prepend ( const T & value )Inserts value at the beginning of the list. Пример: QLinkedList<QString> list; list.prepend("one"); list.prepend("two"); list.prepend("three"); // list: ["three", "two", "one"] This is the same as list.insert(begin(), value). Смотрите также append() и insert(). void QLinkedList::push_back ( const T & value )Эта функция обеспечивает совместимость с STL. Это эквивалентно append(value). void QLinkedList::push_front ( const T & value )Эта функция обеспечивает совместимость с STL. Это эквивалентно prepend(value). int QLinkedList::removeAll ( const T & value )Removes all occurrences of value in the list. Пример: QList<QString> list; list << "sun" << "cloud" << "sun" << "rain"; list.removeAll("sun"); // list: ["cloud", "rain"] Эта функция требует, чтобы у типа значения существовала реализация operator==(). Смотрите также insert(). void QLinkedList::removeFirst ()Removes the first item in the list. This is the same as erase(begin()). See also removeLast() and erase(). void QLinkedList::removeLast ()Removes the last item in the list. See also removeFirst() and erase(). bool QLinkedList::removeOne ( const T & value )Removes the first occurrences of value in the list. Возвращает true, если всё прошло успешно; в противном случае возвращает false. Пример: QList<QString> list; list << "sun" << "cloud" << "sun" << "rain"; list.removeOne("sun"); // list: ["cloud", "sun", "rain"] Эта функция требует, чтобы у типа значения существовала реализация operator==(). Эта функция была введена в Qt 4.4. Смотрите также insert(). int QLinkedList::size () constReturns the number of items in the list. See also isEmpty() and count(). bool QLinkedList::startsWith ( const T & value ) constReturns true if the list is not empty and its first item is equal to value; otherwise returns false. Эта функция была введена в Qt 4.5. Смотрите также isEmpty() и first(). T QLinkedList::takeFirst ()Removes the first item in the list and returns it. If you don't use the return value, removeFirst() is more efficient. See also takeLast() and removeFirst(). T QLinkedList::takeLast ()Removes the last item in the list and returns it. If you don't use the return value, removeLast() is more efficient. See also takeFirst() and removeLast(). std::list<T> QLinkedList::toStdList () constReturns a std::list object with the data contained in this QLinkedList. Пример: QLinkedList<double> list; list << 1.2 << 0.5 << 3.14; std::list<double> stdlist = list.toStdList(); Эта функция была введена в Qt 4.1. See also fromStdList(). bool QLinkedList::operator!= ( const QLinkedList<T> & other ) constReturns true if other is not equal to this list; otherwise returns false. Two lists are considered equal if they contain the same values in the same order. This function requires the value type to implement operator==(). Смотрите также operator==(). QLinkedList<T> QLinkedList::operator+ ( const QLinkedList<T> & other ) constReturns a list that contains all the items in this list followed by all the items in the other list. Смотрите также operator+=(). QLinkedList<T> & QLinkedList::operator+= ( const QLinkedList<T> & other )Appends the items of the other list to this list and returns a reference to this list. Смотрите также operator+() и append(). QLinkedList<T> & QLinkedList::operator+= ( const T & value )Это перегруженная функция. Appends value to the list. QLinkedList<T> & QLinkedList::operator<< ( const QLinkedList<T> & other )Appends the items of the other list to this list and returns a reference to this list. See also operator+=() and append(). QLinkedList<T> & QLinkedList::operator<< ( const T & value )Это перегруженная функция. Appends value to the list. QLinkedList<T> & QLinkedList::operator= ( const QLinkedList<T> & other )Assigns other to this list and returns a reference to this list. bool QLinkedList::operator== ( const QLinkedList<T> & other ) constReturns true if other is equal to this list; otherwise returns false. Two lists are considered equal if they contain the same values in the same order. This function requires the value type to implement operator==(). Смотрите также operator!=(). Связанные нечлены классаQDataStream & operator<< ( QDataStream & out, const QLinkedList<T> & list )Writes the linked list list to stream out. Эта функция требует, чтобы у типа значения была реализация operator<<(). Смотрите также Формат операторов QDataStream. QDataStream & operator>> ( QDataStream & in, QLinkedList<T> & list )Reads a linked list from stream in into list. Эта функция требует, чтобы у типа значения была реализация operator>>(). Смотрите также Формат операторов QDataStream. |
Попытка перевода Qt документации. Если есть желание присоединиться, или если есть замечания или пожелания, то заходите на форум: Перевод Qt документации на русский язык... Люди внесшие вклад в перевод: Команда переводчиков |