From 4f0bd0d4f9b79434376d3afb09fc56fb819c70f0 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 21 Nov 2022 13:27:29 +0100 Subject: [PATCH] Documentation: Fix information on how to iterate over lists MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove the outdated code used for QStringList and point QStringList and QList to the containers page. Task-number: QTBUG-108687 Change-Id: I6fae6410ca759f91da85832ddb9f24e8a0ce202b Reviewed-by: Paul Wicking Reviewed-by: MÃ¥rten Nordheim Reviewed-by: Marc Mutz (cherry picked from commit 4a6ce541c59cfaabb5c68066d0e19912032e48df) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/doc/snippets/qstringlist/main.cpp | 18 ----------------- src/corelib/text/qstringlist.cpp | 20 +------------------ src/corelib/tools/qlist.qdoc | 16 +-------------- 3 files changed, 2 insertions(+), 52 deletions(-) diff --git a/src/corelib/doc/snippets/qstringlist/main.cpp b/src/corelib/doc/snippets/qstringlist/main.cpp index fa3540d8cee..d2175aafb50 100644 --- a/src/corelib/doc/snippets/qstringlist/main.cpp +++ b/src/corelib/doc/snippets/qstringlist/main.cpp @@ -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" diff --git a/src/corelib/text/qstringlist.cpp b/src/corelib/text/qstringlist.cpp index 2c0dc77a5a0..347a89cfa91 100644 --- a/src/corelib/text/qstringlist.cpp +++ b/src/corelib/text/qstringlist.cpp @@ -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. QStringList also provide the - QMutableStringListIterator class which is a type definition for - QMutableListIterator. + See \l {Iterating over Containers}. \section1 Manipulating the Strings diff --git a/src/corelib/tools/qlist.qdoc b/src/corelib/tools/qlist.qdoc index e8e5a735967..e1c917bbc48 100644 --- a/src/corelib/tools/qlist.qdoc +++ b/src/corelib/tools/qlist.qdoc @@ -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