It is very import. I used lots of time to start my first VTK project. test
Set surface for the project
QSurfaceFormat::setDefaultFormat(QVTKOpenGLNativeWidget::defaultFormat());
Initial module
VTK_MODULE_INIT(vtkRenderingOpenGL2); // VTK was built with vtkRenderingOpenGL2
VTK_MODULE_INIT(vtkInteractionStyle);
VTK_MODULE_INIT( vtkRenderingFreeType );
VTK_MODULE_INIT(vtkRenderingContextOpenGL2);
VTK_MODULE_INIT(vtkRenderingGL2PSOpenGL2);
the real example to create a VTK Object and show
//step 1, create a data source;
vtkCylinderSource *cylinder = vtkCylinderSource::New();
cylinder->SetHeight( 3.0 );
cylinder->SetRadius( 1.0 );
cylinder->SetResolution( 4 );
//step 2: map data to a pipeline
vtkPolyDataMapper *cylinderMapper = vtkPolyDataMapper::New();
cylinderMapper->SetInputConnection( cylinder->GetOutputPort() );
//step 3: create a actor and represente the pipeline
vtkActor *actor = vtkActor::New();
actor->SetMapper( cylinderMapper );
//step4 :create a render and set the actor to it
vtkRenderer *render= vtkRenderer::New();
render->AddActor( actor );
render->SetBackground( 0.1, 0.2, 0.4 );
//step 5: set it to a window:
auto vw = new QVTKOpenGLWidget(this) ;
vtkRenderWindow *renWin = vw->GetRenderWindow();
ui->tabWidget->addTab( vw, "My Cylinder");
renWin->AddRenderer( render );
renWin->SetSize( 300, 300 );