Documentation: Fix information on how to iterate over lists

Remove the outdated code used for QStringList and point
QStringList and QList to the containers page.

Pick-to: 6.4 6.2
Task-number: QTBUG-108687
Change-Id: I6fae6410ca759f91da85832ddb9f24e8a0ce202b
Reviewed-by: Paul Wicking <paul.wicking@qt.io>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
bb10
Friedemann Kleint 2022-11-21 13:27:29 +01:00
parent 39d86e05e1
commit 4a6ce541c5
3 changed files with 2 additions and 52 deletions

View File

@ -22,24 +22,6 @@ Widget::Widget(QWidget *parent)
fonts << "Courier" << "Verdana";
//! [0b]
//! [1]
for (int i = 0; i < fonts.size(); ++i)
cout << fonts.at(i).toLocal8Bit().constData() << Qt::endl;
//! [1]
//! [2]
QStringListIterator javaStyleIterator(fonts);
while (javaStyleIterator.hasNext())
cout << javaStyleIterator.next().toLocal8Bit().constData() << Qt::endl;
//! [2]
//! [3]
QStringList::const_iterator constIterator;
for (constIterator = fonts.constBegin(); constIterator != fonts.constEnd();
++constIterator)
cout << (*constIterator).toLocal8Bit().constData() << Qt::endl;
//! [3]
//! [4]
QString str = fonts.join(", ");
// str == "Arial, Helvetica, Times, Courier"

View File

@ -84,25 +84,7 @@ QT_BEGIN_NAMESPACE
\section1 Iterating Over the Strings
To iterate over a list, you can either use index positions or
QList's Java-style and STL-style iterator types:
Indexing:
\snippet qstringlist/main.cpp 1
Java-style iterator:
\snippet qstringlist/main.cpp 2
STL-style iterator:
\snippet qstringlist/main.cpp 3
The QStringListIterator class is simply a type definition for
QListIterator<QString>. QStringList also provide the
QMutableStringListIterator class which is a type definition for
QMutableListIterator<QString>.
See \l {Iterating over Containers}.
\section1 Manipulating the Strings

View File

@ -129,21 +129,7 @@
support \c operator==(). These requirements are documented on a
per-function basis.
Like the other container classes, QList provides \l{Java-style iterators}
(QListIterator and QMutableListIterator) and \l{STL-style iterators}
(QList::const_iterator and QList::iterator). In practice, iterators are
handy when working with generic algorithms provided by \l{generic
algorithms}{Qt} and the C++ standard library. \l{Java-style iterators} are
provided for backwards compatibility, prefer \l{STL-style iterators} when
writing C++ code.
\note Iterators over a QList, and references to individual elements
within one, cannot be relied on to remain valid when any non-const method
of the QList is called. Accessing such an iterator or reference after
the call to a non-const method leads to undefined behavior. When stability
for iterator-like functionality is required, you should use indexes instead
of iterators as they are not tied to QList's internal state and thus do
not get invalidated.
For iterating over the items, see \l {Iterating over Containers}.
In addition to QList, Qt also provides QVarLengthArray, a very
low-level class with little functionality that is optimized for