[Interest] copying the object in the delegate

Dirk Hohndel dirk at hohndel.org
Sat Oct 19 23:48:37 CEST 2019


Hi there,

So this may be a strange question.

I have a sorted filtered list in C++ that is accessed through a list model
in QML. In the delegate I need to access many of the members of the object
underlying the model. Through properties that should be fairly low
overhead, if I could "cache" that object in QML.

But what seems to happen is that every time I access one of the members of
theobject in the delegate, the data function of the model is called with
the correct index. For complicated but reasonably important reasons, this
actually creates a new C++ object for return back to QML, one member of
that object is accessed and then the object is destroyed.

So, in order to access a 32bit integer member of my object and display
this in my delegate, the model is called, a new object with 20+ distinct
members is created from underlying data structures, only one 32bit integer
is accessd, and the rest is immediately discarded. And that is done for
each of the 20+ distinct members. And I suspect that this is done more
than once because I count ~150 calls to the object constructor from the
data() function of the model to display that delegate - a lot more than
member references are in that code.

That is of course ridiculously inefficient. Even ignoring the issue on my
side that forces me to run the constructor every time the data() function
is called, it seems silly to not just be able to have a local copy of that
object for the delegate QML object which then accesses the members of that
object without calling back to the underlying model.

Is there a way to do that and I just didn't find it when looking?

Thanks

/D


More information about the Interest mailing list