2

Hi stackoverflow family

I'm trying to get vtk working with qt. I should admit that I'm a newbie, so go easy. I'm trying to learn c++ for myself and have chosen the following configuration to get me started;

OS: Windows 7 ultimate
toolkit: QT 5.3.2
IDE: QT Creator 3.2.1
VTK: 6.3.0

I downloaded and extracted the VTK to "C:\vtk-6.3.0" on my computer. I followed the instructions given on VTK's website to build VTK with cmake. I gave cmake the location of the source "C:/vtk-6.3.0" and specified a place to build the libraries "C:/vtk/bin".

Thinking everything had gone smoothly, I proceeded with the simplest example I could get away with, an example without a ui. I got the example from here

RenderWindowNoUiFile.cxx

#include <QApplication> #include <vtkSmartPointer.h> #include <vtkSphereSource.h> #include <vtkPolyDataMapper.h> #include <vtkActor.h> #include <vtkRenderWindow.h> #include <vtkRenderer.h> #include <QVTKWidget.h> int main(int argc, char** argv) { QApplication app(argc, argv); QVTKWidget widget; widget.resize( 256, 256 ); vtkSmartPointer<vtkSphereSource> sphereSource = vtkSmartPointer<vtkSphereSource>::New(); vtkSmartPointer<vtkPolyDataMapper> sphereMapper = vtkSmartPointer<vtkPolyDataMapper>::New(); sphereMapper->SetInputConnection( sphereSource->GetOutputPort() ); vtkSmartPointer<vtkActor> sphereActor = vtkSmartPointer<vtkActor>::New(); sphereActor->SetMapper( sphereMapper ); vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New(); renderer->AddActor( sphereActor ); widget.GetRenderWindow()->AddRenderer( renderer ); widget.show(); app.exec(); return EXIT_SUCCESS; } 

I added my .pro file manually

RenderWindowNoUiFile.pro

QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = RenderWindowNoUiFile TEMPLATE = app SOURCES += RenderWindowNoUiFile.cxx INCLUDEPATH += C:\VTK\bin 

I observed that qt has underlined all of the header files and when I ran the program and I got the error

Projects\RenderWindowNoUiFile\RenderWindowNoUiFile.cxx:3: error: vtkSmartPointer.h: No such file or directory #include <vtkSmartPointer.h> ^ 

Please what I'm I doing wrong?
When I searched for any of the header files, I find each in a different location in the "C:\vtk\bin" or "C:\vtk-6.3.0" folder. Please how do I solve this problem? Can I get all of the header files in a single folder so that I can refer to it in the .pro file? For example if I can get all the header files in a directory called "C:\vtk\header", then I can refer to it in my .pro file as INCLUDEPATH += C:\vtk\header

4
  • 3
    Don't try to use two libraries together before you can use each one individually. You might be taking too big steps. Commented Dec 27, 2015 at 18:38
  • 1
    What you have for C:\VTK\bin is the build folder. The headers will not be there. If you use the INSTALL target to install vtk you will get a folder with the binaries and include. Commented Dec 27, 2015 at 19:03
  • Normally headers are not placed in a bin directory. Check that the headers are at the expected location. Once you get the INCLUDEPATH correct you probably need to add link dependency flags as well. Commented Dec 27, 2015 at 19:09
  • @drescherjm Please can you explain how I can use the INSTALL target to install vtk? Commented Dec 27, 2015 at 19:52

2 Answers 2

1

You kind of touched on it with your comment "can I get all the headers in one directory" That is the setting INCLUDEPATH, but you have it set incorrectly.

There are a few issues in what you are doing.

  • First, your INCLUDEPATH is incorrect. It should be set to the "include" directory of the files that you've installed.

  • Second, you haven't included the library in your build- so even if your include files resolved, you would get link errors. This is because you haven't specified where the binary library files are.

  • Third, you didn't specify if your VTK build was static or dynamic. I'll assume this is dynamic. IF you don't know what this means, please look that up. The big difference is: do you need to also copy a .dll file to where your program is running from. If you have dynamic, the answer is yes.

About the comment a out the install target: with cmake you can set an option to change where it installs the binaries to. So the process goes like this with cmake:

1) Get the sources unpacked to a directory that you like.

2) Run cmake build folder (which you set to bin). What you did was confusing, because the build folder will contain everything: not just binaries, but headers and other install stuff. I usually call it "build"

3) Once cmake configures it may prompt for more configuration. This is where you may want to configure Qt for VTK. In this step you tell cmake where the Qt cmake folders are, so that you can configure VTK to build Qt stuff

4) Now you can change the default install path. By default, when you build the INSTALL project with visual studio (I'll describe below) it installs somewhere in program files. You can change this by setting CMAKE_INSTALL_PREFIX to whatever you want. For example: C:\VTK\install

5) Click generate to generate the visual studio project files or Make files, depending on your build configuration.

6) For visual studio: open the solution in the build directory and build all. When this completes, to install the files (#4) run the INSTALL project.

7) For Make files: run make (if you have multiple cores, use -jX where X is twice number of cores) then make install (don't use -j with make install)

Ok at this point you've compiled and installed the VTK distribution. Now you should fix your paths in your Qt .pro file.

For example:

INSTALLPATH+=C:/VTK/install/include 

I don't know which libs you need, but below you should see the pattern:

LIBS+=-LC:/VTK/install/lib \ -lvtkRenderingCore-6.3 

Now after this, since you have a dynamic build you need to copy the .dll files next to the exe file that you are creating from your Qt project.

Good luck!

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for the response. I'm using mingw and so I followed #7 of your instruction. When I run mingw32-make -j8 in command prompt it build until it is 77% but gives me this error [ 77%] Linking CXX shared library ..\..\bin\libvtkRenderingVolume-6.3.dll [ 77%] Built target vtkRenderingVolume Makefile:126: recipe for target 'all' failed mingw32-make: *** [all] Error 2
@OchiFortune I haven't personally used mingw with these make files, so maybe exclude the -j8. It will be much slower but may avoid the issue you are running into. To be sure your build is clean when you try again I suggest that you delete the build directory and generate again. I highly suggest using visual studio if you are just starting out- there is more info and help for VS than mingw
1

If you use mingw with qt ,you have to compile source of vtk with mingw as you know.In that web page they use vs so I want to warn you about it.When you configure vtk source with cmake you should check "Module_vtkGUISupportQt" and "Module_vtkGUISupportQtOpenGL" options to able to work with qt.Also you have to do some config in Run & Build Options in Qt such as selecting compiler, kits etc.

Notice that choosing a compiler which is released after the release date of the library(in this case vtk) may prevent you from suffering of much errors.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.