[vtkusers] QVTKWidget HelloWorld example?

Michael Rice marice at knology.net
Fri Apr 7 20:06:38 EDT 2006


I don't use CMake for building my VTK + Qt projects, so the following  
is just a guess. You don't say what platform you're using, but on  
some platforms/compilers the order of the libraries matters. Try  
changing your target libraries to:

TARGET_LINK_LIBRARIES(${EXECUTABLE_NAME} QVTK ${QT_LIBRARIES}  
vtkHybrid vtkRendering vtkGraphics)

This is the order they are in for the VTK Qt examples.


On Apr 7, 2006, at 6:28 PM, Carlos Capdepon wrote:

> QVTKWidget HelloWorld example code:
>
> CMakeLists.txt
> CMAKE_MINIMUM_REQUIRED(VERSION 2.0)
> # Project customization.
> SET(PROJECT_NAME "VTK_QT_HW")
> SET(EXECUTABLE_NAME "vtkQtHelloWorld")
> SET(${PROJECT_NAME}_SOURCES vtkQtHello.cxx)
> # Project's name.
> PROJECT(${PROJECT_NAME})
> # Find Visualization Toolkit 5.x
> FIND_PACKAGE(VTK REQUIRED)
> IF(VTK_FOUND)
>  INCLUDE(${VTK_USE_FILE})
>  MESSAGE(STATUS "Visualization Toolkit found.")
> ELSE(VTK_FOUND)
>  MESSAGE(FATAL_ERROR "Cannot build ${PROJECT_NAME} without VTK.   
> Please set VTK_DIR.")
> ENDIF(VTK_FOUND)
> MARK_AS_ADVANCED(VTK_DIR)
> # Find Qt 4.x
> FIND_PACKAGE(QT4 REQUIRED)
> IF(QT_FOUND)
>  INCLUDE(${QT_USE_FILE})
>  MESSAGE(STATUS "Qt4 found.")
> ELSE(QT_FOUND)
>  MESSAGE(FATAL_ERROR "Cannot build ${PROJECT_NAME} without Qt4.")
> ENDIF(QT_FOUND)
> MARK_AS_ADVANCED(QT_QMAKE_EXECUTABLE)
> # Disable deprecated function warning = #pragma warning(disable :  
> 4996)
> ADD_DEFINITIONS(-D_CRT_SECURE_NO_DEPRECATE - 
> D_CRT_NONSTDC_NO_DEPRECATE)
> # Executable's name and sources.
> ADD_EXECUTABLE(${EXECUTABLE_NAME} ${${PROJECT_NAME}_SOURCES})
> # Link the executable to the vtkRendering library.
> SET(VTK_LIBRARIES vtkRendering vtkGraphics vtkHybrid QVTK)
> TARGET_LINK_LIBRARIES(${EXECUTABLE_NAME} ${QT_LIBRARIES} $ 
> {VTK_LIBRARIES})
>
> vtkQtHello.cxx
>  // QVTKWidget Hello World!
>
> #include <QApplication>
> #include <QMainWindow>
>
> #include <QVTKWidget.h>
>
> #include <vtkRenderWindow.h>
> #include <vtkRenderer.h>
> #include <vtkTextSource.h>
> #include <vtkVectorText.h>
> #include <vtkPolyDataMapper.h>
> #include <vtkActor.h>
>
> int main( int argc, char **argv )
> {
>     QApplication app(argc,argv);
>  QMainWindow *mainWindow = new QMainWindow;
>   mainWindow->setFixedSize(640,360);
>
>  QVTKWidget *widget = new QVTKWidget;
>   mainWindow->setCentralWidget(widget);
>
>  vtkTextSource *text = vtkTextSource::New();
>   text->SetText("Hello World!");
>   text->BackingOff();
>  vtkVectorText *vectorText = vtkVectorText::New();
>   vectorText->SetText("QVTKWidget");
>  vtkPolyDataMapper *textMapper = vtkPolyDataMapper::New();
>   textMapper->SetInput(text->GetOutput());
>  vtkPolyDataMapper *vectorTextMapper = vtkPolyDataMapper::New();
>   vectorTextMapper->SetInput(vectorText->GetOutput());
>  vtkActor *textActor = vtkActor::New();
>   textActor->SetMapper(textMapper);
>  vtkActor *vectorTextActor = vtkActor::New();
>   vectorTextActor->SetMapper(vectorTextMapper);
>  vtkRenderer *renderer = vtkRenderer::New();
>   renderer->SetBackground(0.4,0.6,0.8);
>   renderer->AddActor(textActor);
>   renderer->AddActor(vectorTextActor);
>  vtkRenderWindow *renderWindow = vtkRenderWindow::New();
>   renderWindow->AddRenderer(renderer);
>   renderWindow->SetStereoTypeToDresden();
>
>  widget->SetRenderWindow(renderWindow);
>  mainWindow->show();
>  app.aboutQt();
>     return app.exec();
> }
>
> Any answer about QVTKWidgetPlugin linking errors? :-(--
> Un saludo,
> "Carlos Capdepón" < carlos.capdepon at gmail.com>
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the FAQ at: http://www.vtk.org/ 
> Wiki/VTK_FAQ
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers




More information about the vtkusers mailing list