# Interactor and callback: VTK 9.1 + QtQuick

**URL:** https://discourse.vtk.org/t/interactor-and-callback-vtk-9-1-qtquick/8800
**Category:** Support
**Created:** [June 23, 2022, 10:30pm UTC](https://discourse.vtk.org/t/interactor-and-callback-vtk-9-1-qtquick/8800 "2022-06-23T22:30:56Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Parisa\_Rabbani](https://discourse.vtk.org/user_avatar/discourse.vtk.org/parisa_rabbani/32/4295_2.png) [@Parisa\_Rabbani](https://discourse.vtk.org/u/Parisa_Rabbani)
#### Post date: [June 23, 2022, 10:30pm UTC](https://discourse.vtk.org/t/interactor-and-callback-vtk-9-1-qtquick/8800/1 "2022-06-23T22:30:56Z")

</div>

Hi,

I have a simple GUI with VTK+QT that would update the volume constantly. We use it to have 3D live volume rendering.

I am trying to do the same thing with a QtQuick GUI, I faced two issues:  
1- The timer callback that I use for updating the Data, will not work until I move the cursor over the render window.  
2- When I click on the render window, it crashes.

Here’s what I get in the output after it crashes:

Generic Warning: In …\VTK-9.1.0\Source\Rendering\OpenGL2\vtkOpenGLState.cxx, line 539  
at stack loc  
at vtksys::SystemInformation::GetProgramStack  
at vtksys::SystemInformation::GetProgramStack  
at vtkOpenGLState::vtkglDrawBuffer  
at vtkOpenGLRenderWindow::BlitDisplayFramebuffersToHardware  
at vtkOpenGLRenderWindow::Frame  
at vtkGenericOpenGLRenderWindow::Frame  
at vtkRenderWindow::Render  
at vtkOpenGLRenderWindow::Render  
at vtkGenericOpenGLRenderWindow::Render  
at vtkRenderWindowInteractor::Render  
at QQuickVTKRenderWindow::paint  
at QMetaObject::activate  
at QQuickWindowPrivate::renderSceneGraph  
at QSGDefaultLayer::updateTexture  
at QSGDefaultLayer::updateTexture  
at QThread::start  
at BaseThreadInitThunk  
at RtlUserThreadStart

Part of the code the code with the callback, as I am suspecting what I do with vtkRenderWindowInteractor (iren) is not right probably for QML case:

```
m_QQuickvtkrenderItem->renderer()->AddVolume(volume);
m_QQuickvtkrenderItem->renderer()->SetBackground(0.10, 0.10, 0.10);
m_QQuickvtkrenderItem->renderer()->ResetCamera();
m_QQuickvtkrenderItem->update();

vtkSmartPointer<vtkTimerCallback> cb = vtkSmartPointer<vtkTimerCallback>::New();
iren = m_QQuickvtkrenderItem->renderer()->GetRenderWindow()->GetInteractor();

cb->IREN = iren;
cb->IMData = ImData;
cb->Height = height;
cb->Width = width;
cb->Depth = depth;
cb->Nframes = n_frames;
cb->Data = data;
iren->AddObserver(vtkCommand::TimerEvent, cb);
int timerId = iren->CreateRepeatingTimer(0.005);

```

Any help would be much appreciated.

Best,  
Parisa

---

<div class="post-metadata">

### Author: ![Parisa\_Rabbani](https://discourse.vtk.org/user_avatar/discourse.vtk.org/parisa_rabbani/32/4295_2.png) [@Parisa\_Rabbani](https://discourse.vtk.org/u/Parisa_Rabbani)
#### Post date: [July 20, 2022, 10:33pm UTC](https://discourse.vtk.org/t/interactor-and-callback-vtk-9-1-qtquick/8800/2 "2022-07-20T22:33:44Z")

</div>

I managed to solve the two issue above. Just writing it down here in case someone else is facing the same issue.

For issue number 1: in order to have the volume update all the time, not only when the mouse is over the vtk window (Hover). In the callback function I update the QQuickWindow:  
m\_QQuickvtkrenderItem-\>window()-\>update();

For issue number 2: Instead of using vtk timer and vtk interactor, I used Qtimer and update the volume data in the Qtimer’s callback function.
