In QML, it is possible to declare a nested type that can implicitly access the scope of the parent object.
This is not the case when declaring nested types in C++, yes static members are accessible, but there’s no mechanism to implicitly make the connection to parent type instances. Of course, it can be still done manually and at a runtime cost of keeping references, which is how QML is ultimately doing it, but is there a better way?
It is still possible to use meta-programming and achieve that via a static singleton pattern. The downside is obvious – the parent type being a singleton means it can’t be instantiated multiple times, so a new template specialization has to be created for every additional object of that type needed, that’s somewhat viable workaround for having multiple objects of that type during compile time, but not viable for the runtime, plus the downside of potential template bloat.
Is there any way to achieve the best of both worlds – not have to drag a multitude of context object references across each context tree, and have that context object type still instantiable during the runtime?