[vtkusers] QVTKWidget HelloWorld example?

Clinton Stimpson clinton at elemtech.com
Wed Apr 5 13:11:03 EDT 2006


>Date: Wed, 5 Apr 2006 00:36:54 +0200
>From: "Carlos Capdepon" <carlos.capdepon at gmail.com>
>Subject: Re: [vtkusers] QVTKWidget HelloWorld example?
>
>QVTKWidget OK.
>
>QVTKWidgetPlugin link error. WHY?¿?
>  
>
You didn't give the link error, so we can't answer why it doesn't build.

>
>I have tried with this CMakelists.txt
>
>CMAKE_MINIMUM_REQUIRED(VERSION 2.0)
># Project customization.
>SET(PROJECT_NAME "QtHelloWorld")
>SET(EXECUTABLE_NAME "qtHW")
>SET(PROJECT_MAJOR_VERSION 0)
>SET(PROJECT_MINOR_VERSION 1)
>SET(PROJECT_BUILD_VERSION "alpha")
>SET(${PROJECT_NAME}_SOURCE_MAIN_FILE helloworld.cxx)
># Project's name.
>PROJECT(${PROJECT_NAME})
>SET(PROJECT_VERSION
>"${PROJECT_MAJOR_VERSION}.${PROJECT_MINOR_VERSION}.${PROJECT_BUILD_VERSION}")
>MESSAGE(STATUS "Building ${PROJECT_NAME} v${PROJECT_VERSION}.")
>
># 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)
>  
>
How about importing the qmake used when building QVTK?
# import qmake setting from VTK project
SET(QT_QMAKE_EXECUTABLE "${VTK_QT_QMAKE_EXECUTABLE}")
Then do the FIND_PACKAGE(Qt4 REQUIRED)

># Find Qt 4.x
>FIND_PACKAGE(QT4 REQUIRED)
>  
>
Instead, 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)
># Use the include path and library for Qt that is used by VTK.
>#INCLUDE_DIRECTORIES(${QT_INCLUDE_DIR} ${QT_QTGUI_INCLUDE_DIR}
>${QT_QTCORE_INCLUDE_DIR})
># Executable's name and sources.
>ADD_EXECUTABLE(${EXECUTABLE_NAME} ${${PROJECT_NAME}_SOURCE_MAIN_FILE})
># Link the executable to the vtkRendering library.
>TARGET_LINK_LIBRARIES(${EXECUTABLE_NAME}
>  QVTK
>  ${QT_LIBRARIES}
>  vtkRendering
>  vtkGraphics
>  vtkIO
>  vtkCommon
>)
>
>I don't know if it this Cmakelists.txt is incomplete or bad, but QVTKWidget
>goes with my helloworld.cxx
>
>#include <QApplication.h>
>  
>
#include <QApplication>
or
#include <qapplication.h>

>#include <QVTKWidget.h>
>#include <vtkSphereSource.h>
>#include <vtkPolyDataMapper.h>
>#include <vtkActor.h>
>#include <vtkRenderer.h>
>#include <vtkRenderWindow.h>
>#include <vtkRenderer.h>
>
>int main( int argc, char **argv )
>{
>    QApplication app( argc, argv );
>  app.aboutQt();
> QVTKWidget widget;
>  widget.resize(640,384);
>#if QT_VERSION < 0x040000
> app.setMainWidget(&widget);
>#endif
> vtkSphereSource *esferaCircunscrita = vtkSphereSource::New();
>  esferaCircunscrita->SetRadius(1.0);
>  esferaCircunscrita->SetThetaResolution(36);
>  esferaCircunscrita->SetPhiResolution(20);
> vtkPolyDataMapper *esferaCircunscritaMapper = vtkPolyDataMapper::New();
>  esferaCircunscritaMapper->SetInput(esferaCircunscrita->GetOutput());
> vtkActor *esferaCircunscritaActor = vtkActor::New();
>  esferaCircunscritaActor->SetMapper(esferaCircunscritaMapper);
> vtkRenderer *renderer = vtkRenderer::New();
>  renderer->SetBackground(0.4,0.6,0.8);
>  renderer->SetViewport(0.0,0.0,1.0,1.0);
>  renderer->AddActor(esferaCircunscritaActor);
> vtkRenderWindow *renderWindow = vtkRenderWindow::New();
>  renderWindow->AddRenderer(renderer);
>  renderWindow->DoubleBufferOn();
>  renderWindow->SetStereoTypeToDresden();
>  widget.SetRenderWindow(renderWindow);
>  widget.show();
>  app.exec();
>    return 0;
>}
>
>  
>
With those fixes, the project builds fine for me.  If you want more 
help, you'll have to give the exact problem you are having.
If you have link errors, post the exact link errors.

Clint




More information about the vtkusers mailing list