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!