Help with vtkQTWitdgetWidget

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);

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.

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();

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

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

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

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

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

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 .