# Help with vtkQTWitdgetWidget

**URL:** https://discourse.paraview.org/t/help-with-vtkqtwitdgetwidget/8705
**Category:** VR/AR
**Created:** [December 22, 2021, 3:54am UTC](https://discourse.paraview.org/t/help-with-vtkqtwitdgetwidget/8705 "2021-12-22T03:54:55Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![zist8888](https://discourse.paraview.org/user_avatar/discourse.paraview.org/zist8888/32/8240_2.png) [@zist8888](https://discourse.paraview.org/u/zist8888)
#### Post date: [December 22, 2021, 3:54am UTC](https://discourse.paraview.org/t/help-with-vtkqtwitdgetwidget/8705/1 "2021-12-22T03:54:55Z")

</div>

Somebody can help me ,I use vtkQtWidgetWidget in openvr ,when i set ‘SetInteractor’ function, my app will quit. thanks! code like this:  
vtkNew cam;  
vtkNew renderer;  
vtkNew renderWindow;  
renderWindow-\>AddRenderer(renderer);  
renderWindow-\>SetWindowName(“OpenVRTessellatedBoxSource”);  
vtkNew iren;  
iren-\>SetRenderWindow(renderWindow);  
QPushButton hello(“Hello world!”, 0);

vtkNew widget;  
widget-\>CreateDefaultRepresentation();

vtkNew VRRe;  
widget-\>GetQWidgetRepresentation()-\>GetPlaneSource()-\>SetPoint2(-0.5, 0.5, -0.5);  
widget-\>SetWidget(&hello);  
widget-\>SetCurrentRenderer(renderer);  
widget-\>SetInteractor(VRRe);  
widget-\>SetEnabled(1);

---

<div class="post-metadata">

### Author: ![martink](https://discourse.paraview.org/user_avatar/discourse.paraview.org/martink/32/2082_2.png) [@martink](https://discourse.paraview.org/u/martink)
#### Post date: [January 4, 2022, 1:48pm UTC](https://discourse.paraview.org/t/help-with-vtkqtwitdgetwidget/8705/2 "2022-01-04T13:48:47Z")

</div>

It looks like you are starting from the existing test which is good. But your pseudocode leaves out a lot of specifics (such as what all the vtkNew are. My guess is that you are trying to do this in VR but are not explicitly creating the RenderWindow, Renderer, RenderWindowInteractor and Camera for the VR system. So one of them is not correct and is causing a crash.

---

<div class="post-metadata">

### Author: ![zist8888](https://discourse.paraview.org/user_avatar/discourse.paraview.org/zist8888/32/8240_2.png) [@zist8888](https://discourse.paraview.org/u/zist8888)
#### Post date: [January 4, 2022, 2:32pm UTC](https://discourse.paraview.org/t/help-with-vtkqtwitdgetwidget/8705/3 "2022-01-04T14:32:55Z")

</div>

Thank you for reply, I use vtkQtwidgetwidget test demo ,it is good.but I want use vtkQTWidgetWidget in VR,you say VR releated object ,I has created,but still crash.  
use Qt msvc2017 vtk9.0

code like this

> 

vtkOpenVRCamera \* cam = vtkOpenVRCamera::New();  
vtkOpenVRRenderer\* renderer= vtkOpenVRRenderer::New();  
vtkOpenVRRenderWindow\* renderWindow= vtkOpenVRRenderWindow::New();  
renderWindow-\>AddRenderer(renderer);

vtkOpenVRRenderWindowInteractor\* iren= vtkOpenVRRenderWindowInteractor::New();  
iren-\>SetRenderWindow(renderWindow);

renderWindow-\>SetMultiSamples(0);  
renderWindow-\>Initialize();  
renderer-\>SetBackground(0.2, 0.3, 0.4);

renderer-\>ResetCamera();  
renderer-\>GetActiveCamera()-\>Azimuth(30);  
renderer-\>GetActiveCamera()-\>Elevation(30);  
renderer-\>ResetCameraClippingRange();  
renderWindow-\>Render();

vtkQWidgetWidget\* widget= vtkQWidgetWidget::New();  
widget-\>CreateDefaultRepresentation();

QPushButton hello(“Hello world!”, 0);  
widget-\>GetQWidgetRepresentation()-\>GetPlaneSource()-\>SetPoint2(-0.5, 0.5, -0.5);  
widget-\>SetWidget(&hello);

widget-\>SetCurrentRenderer(renderer);  
widget-\>SetInteractor(iren)  
widget-\>SetEnabled(1);  
iren-\>Start();

---

<div class="post-metadata">

### Author: ![martink](https://discourse.paraview.org/user_avatar/discourse.paraview.org/martink/32/2082_2.png) [@martink](https://discourse.paraview.org/u/martink)
#### Post date: [January 4, 2022, 2:57pm UTC](https://discourse.paraview.org/t/help-with-vtkqtwitdgetwidget/8705/4 "2022-01-04T14:57:16Z")

</div>

That looks correct from my quick look, can you try that on VTK master? There are a lot of VR related changes/fixes since vtk 9.0 That may solve it for you? If not a stack trace of the crash would help

---

<div class="post-metadata">

### Author: ![zist8888](https://discourse.paraview.org/user_avatar/discourse.paraview.org/zist8888/32/8240_2.png) [@zist8888](https://discourse.paraview.org/u/zist8888)
#### Post date: [January 4, 2022, 3:25pm UTC](https://discourse.paraview.org/t/help-with-vtkqtwitdgetwidget/8705/5 "2022-01-04T15:25:52Z")

</div>

![2222](https://discourse.paraview.org/uploads/default/original/2X/3/399c83191f3447fbe49b25053b64a25fdcca384b.jpeg)

I have download VTK master and complile, try different version 9.0 \ 9.01\9.02 and 9.1 ,but the question still exit.the crash stack as an appendix.

use Qt 5.12.3

---

<div class="post-metadata">

### Author: ![martink](https://discourse.paraview.org/user_avatar/discourse.paraview.org/martink/32/2082_2.png) [@martink](https://discourse.paraview.org/u/martink)
#### Post date: [January 4, 2022, 3:30pm UTC](https://discourse.paraview.org/t/help-with-vtkqtwitdgetwidget/8705/6 "2022-01-04T15:30:39Z")

</div>

I don;t think vtk master does it that way. It no longer uses an offscreensurface if I recall correctly.

---

<div class="post-metadata">

### Author: ![zist8888](https://discourse.paraview.org/user_avatar/discourse.paraview.org/zist8888/32/8240_2.png) [@zist8888](https://discourse.paraview.org/u/zist8888)
#### Post date: [January 4, 2022, 3:38pm UTC](https://discourse.paraview.org/t/help-with-vtkqtwitdgetwidget/8705/7 "2022-01-04T15:38:25Z")

</div>

In vtk9.02, crash code like this:  
// handle any setup required, only call when OpenGL context is active  
void vtkQWidgetTexture::AllocateFromWidget()  
{  
if (this-\>OffscreenSurface && this-\>Framebuffer)  
{  
return;  
}

// the Qt code can modify a lot of OpenGL State  
// some of which we may want to preserve  
auto state = this-\>Context-\>GetState();  
vtkOpenGLState::ScopedglEnableDisable state0(state, GL\_BLEND);  
vtkOpenGLState::ScopedglEnableDisable state1(state, GL\_DEPTH\_TEST);  
vtkOpenGLState::ScopedglEnableDisable state2(state, GL\_SCISSOR\_TEST);  
#ifdef GL\_MULTISAMPLE  
vtkOpenGLState::ScopedglEnableDisable state3(state, GL\_MULTISAMPLE);  
#endif  
vtkOpenGLState::ScopedglBlendFuncSeparate state5(state);  
vtkOpenGLState::ScopedglDepthFunc state6(state);  
vtkOpenGLState::ScopedglViewport state7(state);

// typically just created once, maybe no OpenGL  
if (!this-\>OffscreenSurface)  
{  
if (!this-\>Widget)  
{  
return;  
}

```
this->OffscreenSurface = new QOffscreenSurface();
this->OffscreenSurface->create();

this->Scene = new QGraphicsScene();

this->Widget->move(0, 0);
this->Scene->addWidget(this->Widget);

QObject::connect(this->Scene, &QGraphicsScene::changed, this->RedrawMethod);

```

}

// Framebuffer gets freed when ReleaseGraphicsResources is called  
// so re setup as needed  
if (!this-\>Framebuffer)  
{  
this-\>Framebuffer =  
new QOpenGLFramebufferObject(this-\>Widget-\>width(), this-\>Widget-\>height(), GL\_TEXTURE\_2D);  
this-\>RedrawMethod();  
}  
}

I dont konw where are the problem

---

<div class="post-metadata">

### Author: ![zist8888](https://discourse.paraview.org/user_avatar/discourse.paraview.org/zist8888/32/8240_2.png) [@zist8888](https://discourse.paraview.org/u/zist8888)
#### Post date: [January 6, 2022, 3:23am UTC](https://discourse.paraview.org/t/help-with-vtkqtwitdgetwidget/8705/8 "2022-01-06T03:23:34Z")

</div>

As you say,VTK9.1 hasnt use offscrrenSurface,It can run by compling by msvc2017. Thanks very much

---

<div class="post-metadata">

### Author: ![zist8888](https://discourse.paraview.org/user_avatar/discourse.paraview.org/zist8888/32/8240_2.png) [@zist8888](https://discourse.paraview.org/u/zist8888)
#### Post date: [January 6, 2022, 3:37am UTC](https://discourse.paraview.org/t/help-with-vtkqtwitdgetwidget/8705/9 "2022-01-06T03:37:30Z")

</div>

But I have other problem, At VTK9.1 branch,in OpenVR/Testing medical.cxx run crach. when I modify it which can run ,but render volume will follow by headset rotate,I want the volume which dont move when i rotate my headset .
