QQmlWebChannel: port away from Q_FOREACH [1/2]: loop over registeredObjects


The registeredObjects_clear() function is only invoked from the
QQmlListProperty on which it was installed, so it's highly unlikely to
recurse into registeredObjects_append(), which is the only other
modifier of the container, besides registeredObjects_clear().

This author cannot rule that out, however, but what is already clear
from the code is that if clear() _were_ to recurse into append(), then
clear() would clear those objects append()ed without having
deregisterObject()'ed them, which is objectively wrong.

By using a "consume loop" (loop over std::exchange(c, {})), at least
we will detect the issue going forward, as a clear()ed list will
suddenly have count() > 0.

Note to reviewers: if you grep registeredObjects, you will find hits
outside of qqmlwebchannel.cpp. Those are from a QHash, different from
the QList looped over here. Proof: QQmlWebChannelPrivate is defined in
the .cpp file, so it cannot be accessed outside the TU, except by the
QQmlListProperty it is backing.

Amends 003596fad52690127afca0d7025b62bad7fd013e (5.4; but that just
seems to have renamed the RHS of the Q_FOREACH). Still, much further
back than we need.

Task-number: QTBUG-115802
Pick-to: 6.11
Change-Id: I49b959a1ada5630dbfb8b2bba2c3150bae49d491
Reviewed-by: Arno Rehn <a.rehn@menlosystems.com>
commit47ed61a62f683cb43d2162530360d31177ed7491
parent10deb4f454ba13eca29eb4c39d3fe0cc60490f66
authorMarc Mutz <marc.mutz@qt.io>
committerMarc Mutz <marc.mutz@qt.io>
commit timeWed, 25 Mar 2026 09:35:02 +0100