summaryrefslogtreecommitdiffstats
path: root/src/corelib/doc/snippets
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2025-09-26 11:31:04 +0200
committerUlf Hermann <ulf.hermann@qt.io>2025-12-02 16:01:49 +0100
commit9adaf8505a9eb9d7acb7fee6aeac5341aa24a074 (patch)
treed4e3875f77c590de887d5ff11a32ca699cce4426 /src/corelib/doc/snippets
parentcb8bb93242a57902f1cafcb0754252575ca180c8 (diff)
Core: Provide non-broken metacontainer iterables
QSequentialIterable and QAssociativeIterable are incapable of providing operator[] on their iterators because the references used by those iterators are not actually stable when the iterator is modified. The only way to fix this in a binary compatible way is to provide a complete set of new iterables and iterators. These are implemented in qmeta{association|sequence}.h and exposed through QMeta{Association|Sequence}::Iterable. In order to give users a convenient way to include those, we instruct syncqt to regard qmeta{association|sequence}.h as header to use in order to provide QMetaSequence and QMetaAssociation. These headers are the natural choice anyway. qmetacontainer.h still has to hold the (now incomplete) declarations for QMetaSequence and QMetaAssociation so that we remain source compatible. The new iterables offer a more consistent set of accessor methods and deprecate some of the old accessor methods. It makes little sense to add or remove a value from/to an iterable at an unspecified place. The new sequential iterable offers the more familiar append/prepend and removeFirst/removeLast methods. Finally, the new iterables warn when taking a slow code path that synthesizes operations not avaible on the actual container using iterators. There generally is a reason for those operations to not be available and we shouldn't second-guess the choices made by the authors of the container. For now, we have to keep those code paths intact to remain compatible with QSequentialIterable and QAssociativeIterable. Task-number: QTBUG-140181 Change-Id: I2f4c32716951fa023ae1fb8028d1a87e4c85c3a0 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/corelib/doc/snippets')
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_kernel_qvariant.cpp16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/corelib/doc/snippets/code/src_corelib_kernel_qvariant.cpp b/src/corelib/doc/snippets/code/src_corelib_kernel_qvariant.cpp
index e23f6c9d103..1d7a3fa6409 100644
--- a/src/corelib/doc/snippets/code/src_corelib_kernel_qvariant.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_kernel_qvariant.cpp
@@ -7,8 +7,8 @@
#include <QVariant>
#include <QColor>
#include <QPalette>
-#include <QSequentialIterable>
-#include <QAssociativeIterable>
+#include <QMetaSequence>
+#include <QMetaAssociation>
QString tr(const char *s)
{
@@ -125,14 +125,14 @@ QVariant examples()
QVariant variant = QVariant::fromValue(intList);
if (variant.canConvert<QVariantList>()) {
- QSequentialIterable iterable = variant.value<QSequentialIterable>();
+ QMetaSequence::Iterable iterable = variant.value<QMetaSequence::Iterable>();
// Can use C++11 range-for:
for (const QVariant &v : iterable) {
qDebug() << v;
}
// Can use iterators:
- QSequentialIterable::const_iterator it = iterable.begin();
- const QSequentialIterable::const_iterator end = iterable.end();
+ QMetaSequence::Iterable::const_iterator it = iterable.begin();
+ const QMetaSequence::Iterable::const_iterator end = iterable.end();
for ( ; it != end; ++it) {
qDebug() << *it;
}
@@ -149,14 +149,14 @@ QVariant examples()
QVariant variant = QVariant::fromValue(mapping);
if (variant.canConvert<QVariantHash>()) {
- QAssociativeIterable iterable = variant.value<QAssociativeIterable>();
+ QMetaAssociation::Iterable iterable = variant.value<QMetaAssociation::Iterable>();
// Can use C++11 range-for over the values:
for (const QVariant &v : iterable) {
qDebug() << v;
}
// Can use iterators:
- QAssociativeIterable::const_iterator it = iterable.begin();
- const QAssociativeIterable::const_iterator end = iterable.end();
+ QMetaAssociation::Iterable::const_iterator it = iterable.begin();
+ const QMetaAssociation::Iterable::const_iterator end = iterable.end();
for ( ; it != end; ++it) {
qDebug() << *it; // The current value
qDebug() << it.key();