You are not logged in.

Dear visitor, welcome to If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.


Tuesday, October 17th 2006, 6:13pm

Tutorial for using Qt with VTK


I am a newbie in VTK and Qt. For some time now,I have been trying to use VTK with Qt but faced a lot of problems getting started and configuring them. In the end, it worked(thanks to Anja Ende,Clinton Stimpson and everyone who helped me get started). I am writing down the procedure to get VTK to work with Qt in visual studio 2005 environment. Hopefully this document will help other newbies save a lot of time.

I have tested the following procedure with MS Visual Studio 2005 Professional on Windows XP Pro X64.

1). Install and get Qt working as per the instructions here:
This works fine and you can start using Qt with visual studio(for those who just want to use Qt with Visual Studio, this is how we do it!)

2). Install and configure VTK using Cmake with (a) VTK_USE_GUISUPPORT option and (b) VTK_USE_QVTK option, set to 'ON'
If Qt is installed after VTK, you will need to reconfigure VTK to find Qt.

3).Now it's time to test the configuration with a code which uses both Qt and VTK. You can try it with the example in VTK source( ../Examples/GUI/Qt/Imageviewer). Copy this code(only the cxx file) to a new directory.

4) I use 'qmake' to generate build files. The method to build this example using qmake is:
(a) open visual studio command prompt, go to the directory containing the cxx file and type: qmake -project
this makes a '.pro' file. Open this file in an editor and modify it as below-
# Automatically generated by qmake (2.00a) Wed Oct 11 17:14:01 2006

TEMPLATE = vcapp # this was originally 'app' modify it to 'vcapp'
INCLUDEPATH += . # here include the path to all the directories containing the header files
LIBS += # add this line and include all the libraries(Qt and VTK) needed for the application

# Input
SOURCES += main.cxx
(b)Save the .pro file and run qmake from the command prompt again. This will generate a '.vcproj' file. Open this file in visual studio and build it there. If you included all the libraries and include paths, this should build and run perfectly.

I used qmake for building, because I didn't know how to do it with Cmake. But if the experts here can throw light on that it would help many. Also if someone knows of any other way(probably easier and smarter) to use Qt with VTK, please add to this document.



Thursday, May 10th 2007, 6:04pm

RE: Tutorial for using Qt with VTK

Hi Ashish,
Thanks for posting those details. I am trying to follow those instructions and am running into problems building QVTK. Error messages follow. Did you have any trouble building VTK?

1>------ Build started: Project: QVTK, Configuration: Debug Win32 ------
1>Generating moc_vtkEventQtSlotConnect.cxx
1>Generating moc_QVTKWidget.cxx
1>c1xx : fatal error C1083: Cannot open source file: '.\moc_vtkEventQtSlotConnect.cxx': No such file or directory
1>c1xx : fatal error C1083: Cannot open source file: '.\moc_QVTKWidget.cxx': No such file or directory
1>Generating Code...
1>Build log was saved at "file://c:\VTK\vcc_build\GUISupport\Qt\QVTK.dir\Debug\BuildLog.htm"
1>QVTK - 2 error(s), 0 warning(s)

VTK Build summary:
========== Build: 1 succeeded, 3 failed, 47 up-to-date, 6 skipped


Thursday, May 10th 2007, 8:30pm

RE: Tutorial for using Qt with VTK

Hi Mark,

I didn't face any problems building QVTK. Also I have stopped using 'qmake' and use 'cmake' these days.Can you give me more details as to what you have done so far and at what step are you getting the errors? Are you able to test run a simple Qt code?



Monday, February 16th 2009, 8:41am

VTK with QTcreator

Hi Ashish,

I installed VTK and successfully built all the examples ( specially the GUI/Qt)... everything is working fine when compiled with CMAKE

now l try to compile the same examples with Qtcreator and his qmake funtion... doesn't work

I updated my .pro with the includepath and library ... but doesn't work.

do you have a simple .pro so l can check if l don't miss anything ??

also l'm using mingwin ....



my .pro:
# Input
SOURCES += main.cxx

Compile messages:
Starting: C:/Qt/QtCreator/mingw/bin/mingw32-make.exe debug -w
mingw32-make: Entering directory `C:/Documents and Settings/Michael/Desktop/Project/Qt_creator/vtk'
C:/Qt/QtCreator/mingw/bin/mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory `C:/Documents and Settings/Michael/Desktop/Project/Qt_creator/vtk'
g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"c:\Qt\QtCreator\qt\include\QtCore" -I"c:\Qt\QtCreator\qt\include\QtCore" -I"c:\Qt\QtCreator\qt\include\QtGui" -I"c:\Qt\QtCreator\qt\include\QtGui" -I"c:\Qt\QtCreator\qt\include" -I"c:\VTK\bin" -I"c:\VTK\include\vtk-5.2" -I"c:\Qt\QtCreator\qt\include\ActiveQt" -I"debug" -I"." -I"c:\Qt\QtCreator\qt\mkspecs\win32-g++" -o debug\main.o main.cxx
mingw32-make[1]: Leaving directory `C:/Documents and Settings/Michael/Desktop/Project/Qt_creator/vtk'
mingw32-make: Leaving directory `C:/Documents and Settings/Michael/Desktop/Project/Qt_creator/vtk'
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
mingw32-make[1]: *** [debug/main.o] Error 3
mingw32-make: *** [debug] Error 2
Exited with code 2.
Error while building project vtk
When executing build step 'Make'


Wednesday, March 11th 2009, 1:46am

hello ,everyone

hello, everyone, i am a foreigner, and i am poor in English, so forgive me my English.

So i want to ask Michael , have your solved your problem with qtcreator to compile VTK, if you have, could you tell me how to write .pro , and do you have some vtk electrical books ? In my country, so few information about vtk, and please send me some of them , thank you very much! And my email is : =)


Friday, April 24th 2009, 10:13pm

QtCreator + QT + VTK in Linux

Hi, just wanted to share my experience on a jump start with using Qt+VTK.
As I don't have experience with using Qt I decided to go the easiest possible way - downloaded Qt4 and the QtCreator.
The steps I took next:
1. Built Qt4 from source and installed it.
2. Added /usr/local/Trolltech to my PATH environment variable
3. Downloaded the source for VTK 5.4
4. Launched ccmake in the root of the source tree.
6. Pressed "c" to configure in ccmake, and specified the version of Qt 4.0.
7. After configuring in ccmake, launched cmake, and then make and make install.
8. The needed QVTKWidget.h will be in the /usr/bin/local/include/vtk-5.4.
9. Now we launch QtCreator and create the simple application.
10. In the mainwindow.h I add these headers:

Source code

#include <QVTKWidget.h> 
#include <vtkRenderer.h> 
#include <vtkRenderWindow.h>

And these members:

Source code

QVTKWidget* vtkWidget;     
vtkRenderer* ren;

11. In the mainwindow.cpp I added this code in the constructor:

Source code

MainWindow::MainWindow(QWidget *parent)     
: QMainWindow(parent), ui(new Ui::MainWindowClass) {     
vtkWidget = new QVTKWidget(this,QFlag(0));     
ren = vtkRenderer::New();     
ren->Render(); }

And destructor:

Source code

MainWindow::~MainWindow() {     
delete vtkWidget;     
delete ui;  }

As you see above I have added a verticalLayout to my form - it has some more controls, and the widget I am adding goes to the bottom.

12. In the .pro file I added these:

Source code

  LIBS    += -L/usr/local/lib/vtk-5.4 -lvtkCommon -lvtksys -lQVTK -lvtkQtChart -lvtkViews -lvtkWidgets -lvtkInfovis -lvtkRendering -lvtkGraphics -lvtkImaging -lvtkIO -lvtkFiltering -lvtklibxml2 -lvtkDICOMParser -lvtkpng -lvtkpng -lvtktiff -lvtkzlib -lvtkjpeg -lvtkalglib -lvtkexpat -lvtkverdict -lvtkmetaio -lvtkNetCDF -lvtksqlite -lvtkexoIIc -lvtkftgl -lvtkfreetype -lvtkHybrid  

INCLUDEPATH += /usr/local/include/vtk-5.4

13. In the Project->Build settings->Build environment I added a variable LD_LIBRARY_PATH = /usr/local/lib/vtk-5.4 - so that when you launch the application the dynamic linker finds the libraries.
14. After building and running (Press [F5] in Qt creator) it should show you a red QVTKWidget. :)


Saturday, July 4th 2009, 3:58am

tried on window xp, cannot make it work

I followed information here trying to make it work on QT4.5 and vtk5.4 to work on MinGW with qtcreater1.2. I managed to figure out most of the steps based on information on this tutorial. I cannot make it linked right. It always report undefined reference of vtk's class. Can anyone with experience to show me what is wrong here.

I compiled vtk with QT support under MinGW successfully and installed vtk library. It is in static library form. I add both include and library into .pro file.

I am new to qt. Please help here if you know or have similar experience.

Error from the compiler

undefined reference to `vtkActor::New()'


Wednesday, January 13th 2010, 2:36pm

The example I posted uses gcc under linux, so the LIBS and INCLUDEPATH variables as well as the paths (/usr/...) might not be relevant for MinGW compiler. undefined reference vtkActor::New() is for sure the linker error - meaning that the library containing this function is not linked with. check your paths and/or settings needed to be passed to MinGW. I have never used MinGW therefore I can not help you more precisely.


Saturday, June 23rd 2012, 4:54pm

Hey guys,

Sorry to revive a dead thread, but I wanted to expand upon Justadreamer's nice tutorial but for Windows, VTK, and Qt. One of the more obnoxious issues with CMake is that it doesn't create a windows /include folder, so the .pro file needs a bit more work on windows. This assumes that you have set up the windows debug features as noted by Nokia.

1.) Download VTK

2.) Run CMake and select build for Qt with shared libs and other stuff you need. I did QT_Charts as well. Qt can't staticlly link the widgets in Windows, so .dll files it is.

3.) Make sure that the build folder and the source folder don't have spaces in them. It screws up Qt's qmake in step 7.

4.) When it asks for QT_QMAKE_EXECUTABLE point to the qmake .exe FOR THE COMPILER YOU ARE USING. Mine was C:/QtSDK/Desktop/Qt/4.8.1/msvc2010/bin/qmake.exe but if you are using MinGW or another VS2008 or whatever, it will be different

5.) Before compiling the debug, if you are using Microsoft compiler, enable the symbol server following these instructions: This is because when we are debugging in Qt, we are using the Microsoft Symbol Server. If you don't do this, the debug .dlls will cause a crash with a Checksum error; probably from using local debugging info. I personally pointed VS2010 to the same symbol cache that Qt is using just to be on the safe side.

6.) Compile both Release and Debug. I had to use 32 bit versions since at the time of writing, there appears to be a bug with Qt where it can't recognize the 64-bit version of VS2010. Oh well. Qt DOES NOT like mixing debug and release .dll files, so make sure to do both.

7.) Now we can modify the .pro file. In the following example, the VTK_5.10_32 folder is where VS2010 compiled to, and the VTK folder is the raw source code from the VTK SVN repository. Originally, "C_Source_Code" was "C Source Code" and Qt qmake couldn't work with the spaces, so just an FYI.
###VTK 3D Modeling Library
win32:CONFIG(release, debug|release): LIBS += -LY:\C_Source_Code\VTK_5.10_32\bin\Release -lvtkCommon -lvtksys -lQVTK -lvtkViews -lvtkWidgets \
-lvtkInfovis -lvtkRendering -lvtkGraphics -lvtkImaging -lvtkIO -lvtkFiltering \
-lvtklibxml2 -lvtkDICOMParser -lvtkpng -lvtkpng -lvtktiff -lvtkzlib -lvtkjpeg \
-lvtkalglib -lvtkexpat -lvtkverdict -lvtkmetaio -lvtkNetCDF -lvtksqlite -lvtkexoIIc \
-lvtkftgl -lvtkfreetype -lvtkHybrid

else:win32:CONFIG(debug, debug|release): LIBS += -LY:\C_Source_Code\VTK_5.10_32\bin\Debug -lvtkCommon -lvtksys -lQVTK -lvtkViews -lvtkWidgets \
-lvtkInfovis -lvtkRendering -lvtkGraphics -lvtkImaging -lvtkIO -lvtkFiltering \
-lvtklibxml2 -lvtkDICOMParser -lvtkpng -lvtkpng -lvtktiff -lvtkzlib -lvtkjpeg \
-lvtkalglib -lvtkexpat -lvtkverdict -lvtkmetaio -lvtkNetCDF -lvtksqlite -lvtkexoIIc \
-lvtkftgl -lvtkfreetype -lvtkHybrid

###VTK headers
INCLUDEPATH += Y:/C_Source_Code/VTK/GUISupport/Qt
INCLUDEPATH += Y:/C_Source_Code/VTK/Common
INCLUDEPATH += Y:/C_Source_Code/VTK/Filtering
INCLUDEPATH += Y:/C_Source_Code/VTK/Graphics
INCLUDEPATH += Y:/C_Source_Code/VTK/Hybrid
INCLUDEPATH += Y:/C_Source_Code/VTK/Imaging
INCLUDEPATH += Y:/C_Source_Code/VTK/Parallel
INCLUDEPATH += Y:/C_Source_Code/VTK/Patented
INCLUDEPATH += Y:/C_Source_Code/VTK/Rendering
INCLUDEPATH += Y:/C_Source_Code/VTK/Hybrid
###VTK headers built in the qmake process
INCLUDEPATH += Y:/C_Source_Code/VTK_5.10_32
INCLUDEPATH += Y:/C_Source_Code/VTK_5.10_32/Rendering
### VTK Libraries
win32:CONFIG(release, debug|release) : DEPENDPATH += Y:/C_Source_Code/VTK_5.10_32/bin/Release
else:win32:CONFIG(debug, debug|release): DEPENDPATH += Y:/C_Source_Code/VTK_5.10_32/bin/Debug

win32:CONFIG(release, debug|release) : INCLUDEPATH += Y:/C_Source_Code/VTK_5.10_32/bin/Release
else:win32:CONFIG(debug, debug|release): INCLUDEPATH += Y:/C_Source_Code/VTK_5.10_32/bin/Debug

Basically, the above tells Qt to look in one folder for one set of .dll/.lib files based on release or debug.

8.) Add a Vertical Widget to the .ui
9.) Add the code justadreamer posted. If you are running release mode, you are done. If not, go continue on the journey.
10.) Cry and rage because there are more errors :(
11.) On my system, upon running debug, certain .dll files wouldn't load and would halt the debug compilation. If this happens, go back to Visual Studio, right click on the project associated with the failed .dll, and relink only that project.
12.) Debug again, repeat step 11 if needed.
13.) Set a breakpoint and enjoy the red square drawn using VTK, Windows, and Qt. Pat yourself on the back and have a beer :)

Good luck,


Thursday, July 12th 2012, 6:32am

I think most of us will have same view on this.I too want to write a program and it will help me.


Thursday, April 25th 2013, 5:27pm

The example I posted uses gcc under linux, so the LIBS and INCLUDEPATH variables as well as the paths (/usr/...) might not be relevant for MinGW compiler. undefined reference vtkActor::New() is for sure the linker error - meaning that the library containing this function is not linked with. check your paths and/or settings needed to be passed to MinGW. I have never used MinGW therefore I can not help you more precisely.

Actually, even if you are using GCC, it is better to set the libs up like this:

Source code

LIBS += -L/usr/local/lib/vtk-5.10 ${VTK_LIBRARIES}

This approach is much cleaner and works independently of the VTK libraries you configured to be installed because the parameter above contains all of CMAKE's VTK libraries. When I tried the other approach I also got some linker errors, because I was not linking all of the required libraries.

EDIT: I was wrong. The errors disappeared at first, but when I actually started using vtk functions and got rid of the other errors, some link errors were still thrown. In order to solve this, I reverted back to the original LIBS(similar to what you posted) and I further added the /usr/local/lib/vtk-5.10 directory to the LD_LIBRARY_PATH(before I only had an include folder, like you suggested and it was not working).

This post has been edited 2 times, last edit by "Avrdan" (Apr 25th 2013, 6:55pm)