QQuickVTKItem and vtkUserData question

QQuickVTKItem documentation says this for method initializeVTK():

All VTK objects must be stored in the vtkUserData object returned from this method. They will be destroyed if the underlying QSGNode (which must contain all VTK objects) is destroyed.

I’ve found very few working examples of QQuickVTKItem use, including VTK-9.3.1 unit test TestQQuickVTKItem_2.cxx, which includes this implementation:

struct MyConeItem : QQuickVTKItem
{
  struct Data : vtkObject
  {
    // What does this do?
    static Data* New();

    // What does this do?
    vtkTypeMacro(Data, vtkObject);
  };

  void onEndEvent(vtkObject* caller, unsigned long, void*)
  {
    vtkRenderWindow* renderWindow = vtkRenderWindow::SafeDownCast(caller);
    renderWindow->GetRenderers()->GetFirstRenderer()->ResetCamera();
    renderWindow->RemoveObserver(this->endEventTag);
    this->scheduleRender();
  }


 vtkUserData initializeVTK(vtkRenderWindow* renderWindow) override
  {
    auto vtk = vtkNew<Data>();

    // Create a cone pipeline and add it to the view
    vtkNew<vtkRenderer> renderer;
    vtkNew<vtkActor> actor;
    vtkNew<vtkPolyDataMapper> mapper;
    vtkNew<vtkConeSource> cone;
    renderWindow->AddRenderer(renderer);
    mapper->SetInputConnection(cone->GetOutputPort());
    actor->SetMapper(mapper);
    renderer->AddActor(actor);
    renderer->ResetCamera();
    renderer->SetBackground2(0.7, 0.7, 0.7);
    renderer->SetGradientBackground(true);

    endEventTag = renderWindow->AddObserver(vtkCommand::EndEvent, this, &MyConeItem::onEndEvent);

    return vtk;
  }

I see where the vtkUserData vtk is created in the first line of the method, and where it’s returned on the last line - but how are “all VTK objects” - cone, renderer, actor, etc - stored in the user data?
Thanks!

Q: How are all VTK objects stored in the vtkUserData, as required by QQuickVTKItem documentation?
A: In the above VTK-9.1 unit test, THEY ARE NOT.

I posted this question on stackoverflow, and a user provided two more examples of QQuickVTKItem use:

  • QML-VTK-Examples/HighlightPickedActor - A comment in the vtkUserData struct says “Place your persistent VTK items here” in vtkUserData, but no actual items in there.
  • Joker-7-7/MultiViews - this one actually instantiates VTK objects in the vtkUserData and returns that data from initializeVTK(), as required