📄 qlistdata.cpp
字号:
\sa operator+=(), operator-()*//*! \fn QList::iterator QList::iterator::operator+(int j) const Returns an iterator to the item at \a j positions forward from this iterator. (If \a j is negative, the iterator goes backward.) \sa operator-(), operator+=()*//*! \fn QList::iterator QList::iterator::operator-(int j) const Returns an iterator to the item at \a j positions backward from this iterator. (If \a j is negative, the iterator goes forward.) \sa operator+(), operator-=()*//*! \fn int QList::iterator::operator-(iterator other) const Returns the number of items between the item pointed to by \a other and the item pointed to by this iterator.*//*! \class QList::const_iterator \brief The QList::const_iterator class provides an STL-style const iterator for QList and QQueue. QList provides both \l{STL-style iterators} and \l{Java-style iterators}. The STL-style iterators are more low-level and more cumbersome to use; on the other hand, they are slightly faster and, for developers who already know STL, have the advantage of familiarity. QList\<T\>::const_iterator allows you to iterate over a QList\<T\> (or a QQueue\<T\>). If you want to modify the QList as you iterate over it, use QList::iterator instead. It is generally good practice to use QList::const_iterator on a non-const QList as well, unless you need to change the QList through the iterator. Const iterators are slightly faster, and can improve code readability. The default QList::const_iterator constructor creates an uninitialized iterator. You must initialize it using a QList function like QList::constBegin(), QList::constEnd(), or QList::insert() before you can start iterating. Here's a typical loop that prints all the items stored in a list: \code QList<QString> list; list.append("January"); list.append("February"); ... list.append("December"); QList<QString>::const_iterator i; for (i = list.constBegin(); i != list.constEnd(); ++i) cout << *i << endl; \endcode Most QList functions accept an integer index rather than an iterator. For that reason, iterators are rarely useful in connection with QList. One place where STL-style iterators do make sense is as arguments to \l{generic algorithms}. For example, here's how to delete all the widgets stored in a QList\<QWidget *\>: \code QList<QWidget *> list; ... qDeleteAll(list.constBegin(), list.constEnd()); \endcode Multiple iterators can be used on the same list. However, be aware that any non-const function call performed on the QList will render all existing iterators undefined. If you need to keep iterators over a long period of time, we recommend that you use QLinkedList rather than QList. \sa QList::iterator, QListIterator*//*! \fn QList::const_iterator::const_iterator() Constructs an uninitialized iterator. Functions like operator*() and operator++() should not be called on an uninitialized iterartor. Use operator=() to assign a value to it before using it. \sa QList::constBegin() QList::constEnd()*//*! \typedef QList::const_iterator::iterator_category \internal*//*! \typedef QList::const_iterator::difference_type \internal*//*! \typedef QList::const_iterator::value_type \internal*//*! \typedef QList::const_iterator::pointer \internal*//*! \typedef QList::const_iterator::reference \internal*//*! \fn QList::const_iterator::const_iterator(Node *node) \internal*//*! \fn QList::const_iterator::const_iterator(const const_iterator &other) Constructs a copy of \a other.*//*! \fn QList::const_iterator::const_iterator(const iterator &other) Constructs a copy of \a other.*//*! \fn const T &QList::const_iterator::operator*() const Returns the current item. \sa operator->()*//*! \fn const T *QList::const_iterator::operator->() const Returns a pointer to the current item. \sa operator*()*//*! \fn const T &QList::const_iterator::operator[](int j) const Returns the item at position *this + \a{j}. This function is provided to make QList iterators behave like C++ pointers. \sa operator+()*//*! \fn bool QList::const_iterator::operator==(const const_iterator &other) const Returns true if \a other points to the same item as this iterator; otherwise returns false. \sa operator!=()*//*! \fn bool QList::const_iterator::operator!=(const const_iterator &other) const Returns true if \a other points to a different item than this iterator; otherwise returns false. \sa operator==()*//*! \fn bool QList::const_iterator::operator<(const const_iterator& other) const Returns true if the item pointed to by this iterator is less than the item pointed to by the \a other iterator.*//*! \fn bool QList::const_iterator::operator<=(const const_iterator& other) const Returns true if the item pointed to by this iterator is less than or equal to the item pointed to by the \a other iterator.*//*! \fn bool QList::const_iterator::operator>(const const_iterator& other) const Returns true if the item pointed to by this iterator is greater than the item pointed to by the \a other iterator.*//*! \fn bool QList::const_iterator::operator>=(const const_iterator& other) const Returns true if the item pointed to by this iterator is greater than or equal to the item pointed to by the \a other iterator.*//*! \fn QList::const_iterator &QList::const_iterator::operator++() The prefix ++ operator (\c{++it}) advances the iterator to the next item in the list and returns an iterator to the new current item. Calling this function on QList::end() leads to undefined results. \sa operator--()*//*! \fn QList::const_iterator QList::const_iterator::operator++(int) \overload The postfix ++ operator (\c{it++}) advances the iterator to the next item in the list and returns an iterator to the previously current item.*//*! \fn QList::const_iterator &QList::const_iterator::operator--() The prefix -- operator (\c{--it}) makes the preceding item current and returns an iterator to the new current item. Calling this function on QList::begin() leads to undefined results. \sa operator++()*//*! \fn QList::const_iterator QList::const_iterator::operator--(int) \overload The postfix -- operator (\c{it--}) makes the preceding item current and returns an iterator to the previously current item.*//*! \fn QList::const_iterator &QList::const_iterator::operator+=(int j) Advances the iterator by \a j items. (If \a j is negative, the iterator goes backward.) \sa operator-=(), operator+()*//*! \fn QList::const_iterator &QList::const_iterator::operator-=(int j) Makes the iterator go back by \a j items. (If \a j is negative, the iterator goes forward.) \sa operator+=(), operator-()*//*! \fn QList::const_iterator QList::const_iterator::operator+(int j) const Returns an iterator to the item at \a j positions forward from this iterator. (If \a j is negative, the iterator goes backward.) \sa operator-(), operator+=()*//*! \fn QList::const_iterator QList::const_iterator::operator-(int j) const Returns an iterator to the item at \a j positions backward from this iterator. (If \a j is negative, the iterator goes forward.) \sa operator+(), operator-=()*//*! \fn int QList::const_iterator::operator-(const_iterator other) const Returns the number of items between the item pointed to by \a other and the item pointed to by this iterator.*//*! \fn QDataStream &operator<<(QDataStream &out, const QList<T> &list) \relates QList Writes the list \a list to stream \a out. This function requires the value type to implement \c operator<<(). \sa \link datastreamformat.html Format of the QDataStream operators \endlink*//*! \fn QDataStream &operator>>(QDataStream &in, QList<T> &list) \relates QList Reads a list from stream \a in into \a list. This function requires the value type to implement \c operator>>(). \sa \link datastreamformat.html Format of the QDataStream operators \endlink*//*! \fn iterator QList::remove(iterator pos) Use erase() instead.*//*! \fn int QList::remove(const T &t) Use removeAll() instead.*//*! \fn int QList::findIndex(const T& t) const Use indexOf() instead.*//*! \fn iterator QList::find(const T& t) Use indexOf() instead.*//*! \fn const_iterator QList::find (const T& t) const Use indexOf() instead.*//*! \fn iterator QList::find(iterator from, const T& t) Use indexOf() instead.*//*! \fn const_iterator QList::find(const_iterator from, const T& t) const Use indexOf() instead.*//*! \fn QList<T> QList<T>::fromVector(const QVector<T> &vector) Returns a QList object with the data contained in \a vector. Example: \code QVector<double> vect; vect << "red" << "green" << "blue" << "black"; QList<double> list = QVector<T>::fromVector(vect); // list: ["red", "green", "blue", "black"] \endcode \sa fromSet(), toVector(), QVector::toList()*//*! \fn QVector<T> QList<T>::toVector() const Returns a QVector object with the data contained in this QList. Example: \code QStringList list; list << "Sven" << "Kim" << "Ola"; QVector<QString> vect = list.toVector(); // vect: ["Sven", "Kim", "Ola"] \endcode \sa toSet(), fromVector(), QVector::fromList()*//*! \fn QList<T> QList<T>::fromSet(const QSet<T> &set) Returns a QList object with the data contained in \a set. The order of the elements in the QList is undefined. Example: \code QSet<double> set; set << "red" << "green" << "blue" << ... << "black"; QList<double> list = QList<double>::fromSet(set); qSort(list); \endcode \sa fromVector(), toSet(), QSet::toList(), qSort()*//*! \fn QSet<T> QList<T>::toSet() const Returns a QSet object with the data contained in this QList. Since QSet doesn't allow duplicates, the resulting QSet might be smaller than the original list was. Example: \code QStringList list; list << "Julia" << "Mike" << "Mike" << "Julia" << "Julia"; QSet<QString> set = list.toSet(); set.contains("Julia"); // returns true set.contains("Mike"); // returns true set.size(); // returns 2 \endcode \sa toVector(), fromSet(), QSet::fromList()*//*! \fn QList<T> QList<T>::fromStdList(const std::list<T> &list) Returns a QList object with the data contained in \a list. The order of the elements in the QList is the same as in \a list. Example: \code std::list<double> stdlist; list.push_back(1.2); list.push_back(0.5); list.push_back(3.14); QList<double> list = QList<double>::fromStdList(stdlist); \endcode \sa toStdList(), QVector::fromStdVector()*//*! \fn std::list<T> QList<T>::toStdList() const Returns a std::list object with the data contained in this QList. Example: \code QList<double> list; list << 1.2 << 0.5 << 3.14; std::list<double> stdlist = list.toStdList(); \endcode \sa fromStdList(), QVector::toStdVector()*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -