# Usage of QQuickVTKItem::dispatch\_async in QML

**URL:** https://discourse.vtk.org/t/usage-of-qquickvtkitem-dispatch-async-in-qml/15536
**Category:** Support
**Tags:** code
**Created:** [April 22, 2025, 8:43pm UTC](https://discourse.vtk.org/t/usage-of-qquickvtkitem-dispatch-async-in-qml/15536 "2025-04-22T20:43:05Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![excommunicado](https://discourse.vtk.org/user_avatar/discourse.vtk.org/excommunicado/32/9935_2.png) [@excommunicado](https://discourse.vtk.org/u/excommunicado)
#### Post date: [April 22, 2025, 8:43pm UTC](https://discourse.vtk.org/t/usage-of-qquickvtkitem-dispatch-async-in-qml/15536/1 "2025-04-22T20:43:05Z")

</div>

I’ve already posted my issue [here](https://gitlab.kitware.com/vtk/vtk/-/issues/19659).  
VTK developers asked me to move it here.

Lets assume I’m developing a DICOM viewer using volume rendering in VTK.  
To integrate QML with VTK, we have `QQuickVTKItem`.  
Two main concepts of it are `initializeVTK` and `dispatch_async`.

In `initializeVTK` we are supposed to create `vtkObject`, which would store our data (like renderer, rendererWindow, etc)  
In `dispatch_async` we are supposed to perform operations on that data. And `dispatch_async` is the only place where we could do them. As I notices, read-only operations can be done everywhere, but performing modifying operations without wrapping them into `dispatch_async` causes strange things.

So, for example, I need to read DICOM directory and render DICOM stored there.  
We can read parse directory outside of `dispatch_async`, but when we’ve created and initialized  
`vtkDICOMReader` it should be passed to a next steps:

- setting properties of `vtkVolume` (color and piecewise functions)
- setting mapper
- calling `renderer->AddVolume()` and `renderer->ResetCamera()`

(code sample is available by link above. These calls occurs in `SceneVtkData::AddDataSet`)

But these steps could take amount of time, and must be placed inside `dispatch_async`.  
But `dispatch_async` is not async. Its more like `std::launch::deferred` option in `std::async` arguments. Its just a delayed callback which runs synchroniosly and blocks all Qt UI.

The same thing with any other computations which manipulates with the object returned from `QQuickVTKItem::initializeVTK()`.

Is there a way to make it truly async?  
The main issue I want to solve is UI blocking.  
Its so strange that some operation running inside one `QQuickVTKItem` blocks all other controls which are not related to this item. For example, buttons, sliders, etc.

Would be glad to see any help. ☺
