[Development] How qAsConst and qExchange lead to qNN
ulf.hermann at qt.io
Wed Nov 9 16:12:30 CET 2022
let me mention that I've been pondering all that hairy stuff just
recently when trying to come up with a solution for how to map QList<Foo
*> and QQmlListProperty<Foo> to each other without exposing people to
dangling references and without copying and allocating all the time.
One thing we could do is add a special escape hatch to QSpan (or
QQmlListProperty) that makes it easy to retrieve the underlying QList in
the cases where it's just a thin wrapper around a complete QList. That
thing could then be used to implicitly construct a (shared) QList from a
With this, you'd get the old behavior if you just pass QList around.
Your QLists are just wrapped and unwrapped in QSpans when passing Qt's
API boundary. However, you could also pass other things that can be
expressed as QSpan, and new Qt APIs could return QSpans that are not
backed by QLists.
I realize that this proposal has very little to do with std::span. It
also doesn't solve all of my problems with QQmlListProperty, but it
might be part of a solution.
More information about the Development