PDA

View Full Version : QT (not-) working with VTK libraries



floyd.pepper
13th August 2009, 02:11
hi there friendly qt centre,

another newbie question... :o

I'm trying to get vtk working with qt. I should also admit that I'm a nooby, so go easy. I'm trying to learn c++ for myself and have chosen the following configuration to get started;
OS: XP
toolkit: QT 4.5.1
IDE: QT Creator 1.2

VTK: 5.4.0

I downloaded and decompressed VTK "C:\vtk-5.4.0" on my system. I followed the instructions over on QT Forums (http://www.qtforum.org/article/18473/tutorial-for-using-qt-with-vtk.html) to build VTK with cmake. I didn't forget to set VTK_USE_GUISUPPORT and VTK_USE_QVTK. I gave cmake the location of the source "C:/vtk-5.4.0" and specified a place to build the libraries "C:/vtk".

Thinking everything had gone smoothly, I proceeded with the simplest program I could get away with. The main class in my project is called VTK_Example.

main.cpp



#include <QtGui/QApplication>
#include "vtk_example.h"

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
VTK_Example w;
w.show();
return a.exec();
}

VTK_example.cpp

#include "vtk_example.h"
#include <QVTKWidget.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include "ui_vtk_example.h"

VTK_Example::VTK_Example(QWidget *parent)
: QMainWindow(parent), ui(new Ui::VTK_Example)
{
ui->setupUi(this);

QVTKWidget* vtkWidget;
vtkRenderer* ren;
vtkWidget = new QVTKWidget(this,QFlag(0));
ui->verticalLayout->addWidget(vtkWidget);
ui->verticalLayout->update();
ren = vtkRenderer::New();
vtkWidget->GetRenderWindow()->AddRenderer(ren);
ren->SetBackground(1.0,0,0);
ren->Render();
}

VTK_Example::~VTK_Example()
{
delete ui;
}


I included the following lines in my VTK_App.pro


LIBS += -LC:/vtk -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 += C:/vtk


When I try to build this simple program, I get the following errors;



C:/<snip>/code/VTK_App/vtk_example.cpp:2: QVTKWidget.h: No such file or directory
C:/<snip>/code/VTK_App/vtk_example.cpp:2: vtkRenderer.h: No such file or directory
C:/<snip>/code/VTK_App/vtk_example.cpp:2: vtkRenderWindow.h: No such file or directory
...

One of my theories is that cmake hasn't built VTK correctly. My C:\vtk\bin folder is completely empty.

Can anyone shed some light on where I've gone astray?

Any help would be greatly appreciated.

All the best,
floyd

franz
13th August 2009, 08:49
The fact that VTK's bin directory is empty doesn't say much. In general I would expect their stuff to be in c:/vtk/lib and c:/vtk/include. Your vtk include path is probably c:/vtk/include or something like that.

floyd.pepper
13th August 2009, 12:37
Thanks franz,

I also looked around the vtk folder for places that should be in the include path, but the folder does not have an include folder or a lib folder. Here is the contents of my C:/vtk directory


Contents of folder: C:\vtk 13/08/2009 7:31 AM

Date Time Attrib Bytes File name
---------- -------- ------ ---------------- --------
C:\vtk
12/08/2009 3:54:46 PM -D---- bin
12/08/2009 9:28:02 PM -D---- CMake
12/08/2009 9:28:12 PM A----- 70,461 CMakeCache.txt
12/08/2009 9:28:41 PM -D---- CMakeFiles
12/08/2009 3:43:29 PM -D---- CMakeTmp
12/08/2009 3:54:46 PM A----- 11,429 cmake_install.cmake
12/08/2009 9:28:28 PM -D---- Common
12/08/2009 9:28:02 PM A----- 43 CTestCustom.cmake
12/08/2009 3:54:46 PM A----- 1,068 CTestTestfile.cmake
12/08/2009 3:42:03 PM A----- 1,745 DartConfiguration.tcl
12/08/2009 9:28:40 PM -D---- Examples
12/08/2009 9:28:29 PM -D---- Filtering
12/08/2009 9:28:30 PM -D---- GenericFiltering
12/08/2009 9:28:33 PM -D---- Geovis
12/08/2009 9:28:30 PM -D---- Graphics
12/08/2009 9:28:33 PM -D---- GUISupport
12/08/2009 9:28:32 PM -D---- Hybrid
12/08/2009 9:28:29 PM -D---- Imaging
12/08/2009 9:28:32 PM -D---- Infovis
12/08/2009 9:28:31 PM -D---- IO
12/08/2009 9:28:19 PM A----- 53,288 Makefile
12/08/2009 3:53:49 PM A----R 1,108 proj_config.h
12/08/2009 9:28:31 PM -D---- Rendering
12/08/2009 3:42:03 PM -D---- Testing
12/08/2009 3:42:12 PM A----R 1,347 UseVTK.cmake
12/08/2009 9:28:20 PM -D---- Utilities
12/08/2009 9:28:33 PM -D---- Views
12/08/2009 9:28:31 PM -D---- VolumeRendering
12/08/2009 3:41:41 PM A----- 1,392 VTKBuildSettings.cmake
12/08/2009 3:43:32 PM A----R 415 vtkCommonInstantiator.h
12/08/2009 9:28:03 PM A----- 2,978 VTKCompileToolsConfig.cmake
12/08/2009 3:53:57 PM A----R 8,888 VTKConfig.cmake
12/08/2009 3:53:15 PM A----R 752 VTKConfigQt.cmake
12/08/2009 3:53:47 PM A----R 7,632 vtkConfigure.h
12/08/2009 3:43:32 PM A----R 439 vtkFilteringInstantiator.h
12/08/2009 3:43:34 PM A----R 496 vtkGenericFilteringInstantiator.h
12/08/2009 3:43:37 PM A----R 415 vtkGeovisInstantiator.h
12/08/2009 3:43:33 PM A----R 431 vtkGraphicsInstantiator.h
12/08/2009 3:43:36 PM A----R 415 vtkHybridInstantiator.h
12/08/2009 3:43:33 PM A----R 423 vtkImagingInstantiator.h
12/08/2009 3:43:36 PM A----R 423 vtkInfovisInstantiator.h
12/08/2009 3:43:34 PM A----R 383 vtkIOInstantiator.h
12/08/2009 9:28:12 PM A----- 5,784 VTKLibraryDepends.cmake
12/08/2009 3:43:35 PM A----R 439 vtkRenderingInstantiator.h
12/08/2009 9:28:02 PM -D---- vtkstd
12/08/2009 3:42:12 PM A----R 4,890 vtkToolkits.h
12/08/2009 3:43:37 PM A----R 407 vtkViewsInstantiator.h
12/08/2009 3:43:36 PM A----R 487 vtkVolumeRenderingInstantiator.h
12/08/2009 3:43:36 PM A----R 423 vtkWidgetsInstantiator.h
12/08/2009 9:28:32 PM -D---- Widgets
12/08/2009 9:28:20 PM -D---- Wrapping
-------------------
178,401 28 Files

Summary of C:\vtk
Directories = 1
Files = 28
Bytes = 178,401


This is what leads me to believe that VTK has not been built correctly. Also, what should I be looking for?? Should I be looking for some .so files?

Thanks again,
floyd

franz
13th August 2009, 16:26
At least the files you require aren't there. On windows you should be looking for DLL files. Did the vtk build produce any errors?

I might have a shot at this when I get home.

floyd.pepper
13th August 2009, 16:53
Thanks franz,

I think I've found the error...another one of those embarassing newbie mistakes which i'm kicking myself for.

I'm afraid I didn't realise I needed to actually *build* the files that cmake generated! :o

Right now, the files are currently (24%) being built using QT Creator. For those who might also be in a similar situation...here's what I did.

I opened QT Creator...selected 'New Project' and from the list, selected 'Import of Makefile-based Project'.

I then chose a name for the project, vtk and specified the location to be the location of my generated files from cmake, C:\vtk.

The project opened up with the file tree from that folder. I then selected Projects on the left hand side and changed the Toolchain from gcc to mingw.

Now if is building the files and placing the dll's and dll.a files into C:\vtk\bin directory.

I suppose that this is the solution to my problem...but I'll confirm when the build is completed.

Thanks for all the advice franz, but hopefully this will solve the problem.

floyd.pepper
13th August 2009, 22:48
OK...it still has't worked.

I'm having trouble making QT Creator find the libraries. I've appended the pro file with the following


LIBS += -LC:/vtk/bin -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 += C:/vtk


Can anyone tell me what else I need to do? Should I create an environmental variable called LD_LIBRARY_PATH to point to the vtk\bin directory?

Thanks again,
floyd

franz
14th August 2009, 07:15
I think I've found the error...another one of those embarassing newbie mistakes which i'm kicking myself for.

I'm afraid I didn't realise I needed to actually *build* the files that cmake generated! :o

Hey, we live and we learn.


I'm having trouble making QT Creator find the libraries.

Can anyone tell me what else I need to do? Should I create an environmental variable called LD_LIBRARY_PATH to point to the vtk\bin directory?

What you need to do depends on what the exact problem is that you are experiencing. If Qt creator doesn't do the autocompletion or doesn't find the header files, make sure your INCLUDEPATH is correct. If you experience linker errors, then you should double check your libraries, although I think those won't be much of a problem.

floyd.pepper
14th August 2009, 21:28
It appears to be a problem with the INCLUDEPATH. The problem is that I don't have an 'include' folder that contains all the header files.

In CMake I changed the CMAKE_INSTALL_PREFIX to point to a location C:/vtk-build in the hope that I would get an 'include' folder there which would contain all the header files for vtk. How else can I specify the header file? Do I need to locate and specify each header in the INCLUDEPATH? This would mean that my includepath would have as many entries as header files that I am using. I'm sure there must be an easier way?

Thanks in advance for any pointers. Otherwise, have a great weekend!

floyd

franz
17th August 2009, 08:44
I'd just do a search for one or two specific headers you need in the VTK path. I haven't had time to do this myself, but I'm sure that if you do a quick search for vtkRenderer.h or something, you would come up with something useful.

floyd.pepper
17th August 2009, 14:15
Hi Franz,

I did a search as you recommended. I found the header file only in the original source that I downloaded from VTK, "C:\vtk-5.4.2\Rendering". I don't understand how the libraries (dlls) can be built correctly and placed in the C:\vtk\bin folder while the header files are not collected into one folder?

As always, any comments or tips would be really appreciated.

All the best,
floyd



(Apologies for the second post, I felt it was a different problem. I realise that this is not a problem with QT and VTK compatability, but instead seems to have been a problem with how I built VTK. Thanks for the comments.)

floyd.pepper
25th August 2009, 20:06
Is it possible for me to bump this topic?

If we come up with a solution, I would be very grateful.

cheers,

franz
26th August 2009, 21:03
Try:
$ make install
(replace make with whatever make tool you use at the moment)

It might create the include directory for you. I haven't gotten round to trying to build VTK myself.

floyd.pepper
28th August 2009, 19:15
Hi Franz,

I appreciate you getting back to me. I'm not sure how I can make install?

1. After I have generated the files with cmake.
2. I open up qtcreator and create a new project from the Makefile that cmake has just generated.
3. I build the project using mingw; this creates the dll and dll.a in the bin directory. There is no include directory generated.

Can you tell me what else I need to do? Do you think I should use cygwin bash to 'make install'? I presumed that qtcreator and mingw would be able to create the dll's and place all the header files in include directory.

as always, your help is appreciated.

All the best,
floyd

floyd.pepper
28th August 2009, 19:50
ok, slight advance.

Once qtcreator has finished building and created the dlls. I then try to run (I'm thinking that this is the same as 'make install'?)

However, in the run settings it asks me for an executable. What executable would it be looking for?

This problem has me stomped now since Aug 12th...I know Einstein said,'It`s not that I`m so smart, it`s just that I stay with problems longer.' but this is ridiculous.

Cheers,

franz
30th August 2009, 10:58
You can't do make install with qt creator. Open the qt command prompt, cd to the vtk directory and type mingw32-make install. At least, I think it was mingw32-make.

floyd.pepper
31st August 2009, 03:03
Thanks Franz,

You just made my weekend :) That did the trick. I think my problem is solved. I started a qt command prompt and did mingw32-make install and I got everything installed into the 'include', 'lib', 'plugins' and 'bin' directory.

Cheers Franz!

franz
31st August 2009, 12:46
Great! Happy VTK'ing.