Doc: Make QListIterator snippets more robust

qDebug() << i.next();

can become a NOOP if the code is compiled with QT_NO_DEBUG_OUTPUT.

Pick-to: 5.15 6.2 6.3
Fixes: QTBUG-97535
Change-Id: I9085b40ac9b4de2bb06f16e03fd5100902b08d4f
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
This commit is contained in:
Kai Köhne 2022-01-06 14:46:40 +01:00
parent bc3ac007d8
commit 713967ae30
7 changed files with 23 additions and 19 deletions

View File

@ -70,7 +70,7 @@ list << "A" << "B" << "C" << "D";
QListIterator<QString> i(list);
while (i.hasNext())
qDebug() << i.next();
QString s = i.next();
//! [1]
@ -78,7 +78,7 @@ while (i.hasNext())
QListIterator<QString> i(list);
i.toBack();
while (i.hasPrevious())
qDebug() << i.previous();
QString s = i.previous();
//! [2]
@ -216,8 +216,10 @@ foreach (str, values)
QList<QString> values;
...
QListIterator<QString> i(values);
while (i.hasNext())
qDebug() << i.next();
while (i.hasNext()) {
QString s = i.next();
qDebug() << s;
}
//! [16]

View File

@ -53,7 +53,7 @@ QList<float> list;
...
QListIterator<float> i(list);
while (i.hasNext())
qDebug() << i.next();
float f = i.next();
//! [0]
@ -61,7 +61,7 @@ while (i.hasNext())
QListIterator<float> i(list);
i.toBack();
while (i.hasPrevious())
qDebug() << i.previous();
float f = i.previous();
//! [1]
//! [6]
@ -69,7 +69,7 @@ QSet<QString> set;
...
QSetIterator<QString> i(set);
while (i.hasNext())
qDebug() << i.next();
float f = i.next();
//! [6]
@ -77,7 +77,7 @@ while (i.hasNext())
QSetIterator<QString> i(set);
i.toBack();
while (i.hasPrevious())
qDebug() << i.previous();
QString s = i.previous();
//! [7]
@ -86,7 +86,7 @@ QList<float> list;
...
QMutableListIterator<float> i(list);
while (i.hasNext())
qDebug() << i.next();
float f = i.next();
//! [8]
@ -94,7 +94,7 @@ while (i.hasNext())
QMutableListIterator<float> i(list);
i.toBack();
while (i.hasPrevious())
qDebug() << i.previous();
float f = i.previous();
//! [9]
@ -115,7 +115,7 @@ QSet<float> set;
...
QMutableSetIterator<float> i(set);
while (i.hasNext())
qDebug() << i.next();
float f = i.next();
//! [17]
//! [19]

View File

@ -73,8 +73,10 @@ if (!set.contains("ninety-nine"))
//! [4]
QSetIterator<QWidget *> i(set);
while (i.hasNext())
qDebug() << i.next();
while (i.hasNext()) {
QWidget *w = i.next();
qDebug() << w;
}
//! [4]

View File

@ -51,8 +51,8 @@
//! [0]
QDirIterator it("/etc", QDirIterator::Subdirectories);
while (it.hasNext()) {
qDebug() << it.next();
QString dir = it.next();
qDebug() << dir;
// /etc/.
// /etc/..
// /etc/X11

View File

@ -63,7 +63,7 @@ QStringIterator i(string); // implicitly converted to QStringView
//! [1]
while (i.hasNext())
qDebug() << i.next();
uint c = i.next();
//! [1]
}

View File

@ -62,7 +62,7 @@ QFuture<QString> future;
...
QFutureIterator<QString> i(future);
while (i.hasNext())
qDebug() << i.next();
QString s = i.next();
//! [1]
@ -70,7 +70,7 @@ while (i.hasNext())
QFutureIterator<QString> i(future);
i.toBack();
while (i.hasPrevious())
qDebug() << i.previous();
QString s = i.previous();
//! [2]
//! [3]

View File

@ -71,7 +71,7 @@
\image javaiterators1.png
Here's a typical loop for iterating through all the elements of a
QList<QString> in order and printing them to the console:
QList<QString> in order:
\snippet code/doc_src_containers.cpp 1