Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. Add VTK library to Qt project
QtWS25 Last Chance

Add VTK library to Qt project

Scheduled Pinned Locked Moved Solved C++ Gurus
vtk
42 Posts 3 Posters 15.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Please_Help_me_D
    wrote on 3 Dec 2019, 15:57 last edited by
    #1

    Hi,
    I installed VTK-8.2 library with MSVC 64 on Windows 7 x64
    I checked on all the flags where Qt and VTK should work together in CMake while building VTK. The building passed without errors.
    I can see QVTK widget as on picture:
    QVTK.jpg
    But I cannot run any code that would prove me that VTK works. I didn't compiled any examples while building VTK but I'm trying to run the example from: VTK_example and it doesn't work.
    I tried to add all VTK libraries to Qt like:

    LIBS += "C:/apps/MSVC_apps_release/VTK/lib/vtkChartsCore-8.2.lib" \
    "C:/apps/MSVC_apps_release/VTK/lib/vtkCommonColor-8.2.lib" \
    etc... (there are 130 .lib files)
    

    VTK is installed here: C:\apps\MSVC_apps_release\VTK
    libraries: C:\apps\MSVC_apps_release\VTK\lib
    include: C:\apps\MSVC_apps_release\VTK\include\vtk-8.2
    How to run any VTK code to check if it works? I use QMake but I cannot do that with CMake either

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 3 Dec 2019, 16:20 last edited by
      #2

      Hi,

      The VTK dlls are likely not found at run time.

      Go to the Run part of the Project panel and modify the PATH environment variable so that it also contains the folder where the VTK dlls can be found.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      P 1 Reply Last reply 3 Dec 2019, 17:08
      1
      • S SGaist
        3 Dec 2019, 16:20

        Hi,

        The VTK dlls are likely not found at run time.

        Go to the Run part of the Project panel and modify the PATH environment variable so that it also contains the folder where the VTK dlls can be found.

        P Offline
        P Offline
        Please_Help_me_D
        wrote on 3 Dec 2019, 17:08 last edited by Please_Help_me_D 12 Mar 2019, 17:12
        #3

        @SGaist thank you for response
        As I understood I added path var as in the picture:
        Path.jpg
        When I launch the app I get an error:
        error.jpg
        and my main.cpp looks like in the example VTK_example with 2 include added #include "mainwindow.h" #include <QApplication>:

        #include "mainwindow.h"
        #include <QApplication>
        
        #include <vtkActor.h>
        #include <vtkCamera.h>
        #include <vtkCylinderSource.h>
        #include <vtkNamedColors.h>
        #include <vtkPolyDataMapper.h>
        #include <vtkProperty.h>
        #include <vtkRenderWindow.h>
        #include <vtkRenderWindowInteractor.h>
        #include <vtkRenderer.h>
        #include <vtkSmartPointer.h>
        
        #include <array>
        
        int main(int, char *[]) {
          vtkSmartPointer<vtkNamedColors> colors =
              vtkSmartPointer<vtkNamedColors>::New();
        
          // Set the background color.
          std::array<unsigned char, 4> bkg{{26, 51, 102, 255}};
          colors->SetColor("BkgColor", bkg.data());
        
          // This creates a polygonal cylinder model with eight circumferential facets
          // (i.e, in practice an octagonal prism).
          vtkSmartPointer<vtkCylinderSource> cylinder =
              vtkSmartPointer<vtkCylinderSource>::New();
          cylinder->SetResolution(8);
        
          // The mapper is responsible for pushing the geometry into the graphics
          // library. It may also do color mapping, if scalars or other attributes are
          // defined.
          vtkSmartPointer<vtkPolyDataMapper> cylinderMapper =
              vtkSmartPointer<vtkPolyDataMapper>::New();
          cylinderMapper->SetInputConnection(cylinder->GetOutputPort());
        
          // The actor is a grouping mechanism: besides the geometry (mapper), it
          // also has a property, transformation matrix, and/or texture map.
          // Here we set its color and rotate it around the X and Y axes.
          vtkSmartPointer<vtkActor> cylinderActor = vtkSmartPointer<vtkActor>::New();
          cylinderActor->SetMapper(cylinderMapper);
          cylinderActor->GetProperty()->SetColor(
              colors->GetColor4d("Tomato").GetData());
          cylinderActor->RotateX(30.0);
          cylinderActor->RotateY(-45.0);
        
          // The renderer generates the image
          // which is then displayed on the render window.
          // It can be thought of as a scene to which the actor is added
          vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
          renderer->AddActor(cylinderActor);
          renderer->SetBackground(colors->GetColor3d("BkgColor").GetData());
          // Zoom in a little by accessing the camera and invoking its "Zoom" method.
          renderer->ResetCamera();
          renderer->GetActiveCamera()->Zoom(1.5);
        
          // The render window is the actual GUI window
          // that appears on the computer screen
          vtkSmartPointer<vtkRenderWindow> renderWindow =
              vtkSmartPointer<vtkRenderWindow>::New();
          renderWindow->SetSize(300, 300);
          renderWindow->AddRenderer(renderer);
          renderWindow->SetWindowName("Cylinder");
        
          // The render window interactor captures mouse events
          // and will perform appropriate camera or actor manipulation
          // depending on the nature of the events.
          vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
              vtkSmartPointer<vtkRenderWindowInteractor>::New();
          renderWindowInteractor->SetRenderWindow(renderWindow);
        
          // This starts the event loop and as a side effect causes an initial render.
          renderWindow->Render();
          renderWindowInteractor->Start();
        
          return EXIT_SUCCESS;
        }
        
        

        Here is one thing that the path showed in ERROR is the folder where VTK was downloaded. I mean here is VTK downloaded:
        D:\Qt\Downloaded\VTK-8.2.0
        and here it is installed:
        C:\apps\MSVC_apps_release\VTK
        The error complains on the download path. Is that ok?

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 3 Dec 2019, 18:32 last edited by
          #4

          It's PATH, all in capital.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          P 2 Replies Last reply 3 Dec 2019, 18:39
          1
          • S SGaist
            3 Dec 2019, 18:32

            It's PATH, all in capital.

            P Offline
            P Offline
            Please_Help_me_D
            wrote on 3 Dec 2019, 18:39 last edited by Please_Help_me_D 12 Mar 2019, 18:42
            #5
            This post is deleted!
            1 Reply Last reply
            0
            • S SGaist
              3 Dec 2019, 18:32

              It's PATH, all in capital.

              P Offline
              P Offline
              Please_Help_me_D
              wrote on 3 Dec 2019, 19:17 last edited by
              #6

              @SGaist I have PATH variable only if I check on "Purely system environment" and in this case after I add path to the VTK/bin (C:\apps\MSVC_apps_release\VTK\bin) folder then I get an error:
              :-1: error: cannot open C:\Windows\main.obj.7068.0.jom for write
              And it doesn't matter whether I add path to the VTK/bin or not. In "Purely system environment" mode my app gives the same error :(

              1 Reply Last reply
              0
              • S Offline
                S Offline
                SGaist
                Lifetime Qt Champion
                wrote on 3 Dec 2019, 19:35 last edited by
                #7

                That looks like a build problem because it tries to write file somewhere it should not.

                Did you do that in the Run part only ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                P 4 Replies Last reply 3 Dec 2019, 19:41
                0
                • S SGaist
                  3 Dec 2019, 19:35

                  That looks like a build problem because it tries to write file somewhere it should not.

                  Did you do that in the Run part only ?

                  P Offline
                  P Offline
                  Please_Help_me_D
                  wrote on 3 Dec 2019, 19:41 last edited by
                  #8

                  @SGaist what is Run part? sorry

                  1 Reply Last reply
                  0
                  • S SGaist
                    3 Dec 2019, 19:35

                    That looks like a build problem because it tries to write file somewhere it should not.

                    Did you do that in the Run part only ?

                    P Offline
                    P Offline
                    Please_Help_me_D
                    wrote on 3 Dec 2019, 20:05 last edited by Please_Help_me_D 12 Mar 2019, 22:55
                    #9

                    @SGaist Seems to me that partially problem was solved.
                    I added to the main file:

                    #include <vtkAutoInit.h>
                    VTK_MODULE_INIT(vtkRenderingOpenGL2);
                    VTK_MODULE_INIT(vtkInteractionStyle);
                    

                    I found it here link_1 and here link_2. I can run it only if both PATH and Path variables include path to VTK/bin and "Pure system environment" is checked off.
                    Here is the result:
                    Picture.jpg
                    As you can see I get some error and warning. What do you think of this?
                    Here is full error:
                    ERROR: In D:\Qt\Downloaded\VTK-8.2.0\Rendering\OpenGL2\vtkWin32OpenGLRenderWindow.cxx, line 734
                    vtkWin32OpenGLRenderWindow (000000000016F1C0): We have determined that your graphics system is an Intel SandyBridge based system. These systems only partially support VTK. If you encounter any issues please make sure your graphics drivers from Intel are up to date.

                    1 Reply Last reply
                    0
                    • S SGaist
                      3 Dec 2019, 19:35

                      That looks like a build problem because it tries to write file somewhere it should not.

                      Did you do that in the Run part only ?

                      P Offline
                      P Offline
                      Please_Help_me_D
                      wrote on 4 Dec 2019, 01:42 last edited by
                      #10

                      @SGaist I use laptop and I have two videocards: Intel (native) and Nvidia (external). The error appears only when I run the app with native Intel videocard. If I run it with Nvidia then there is no error. So I think the question is solved. Thank you one more time :)

                      1 Reply Last reply
                      0
                      • S SGaist
                        3 Dec 2019, 19:35

                        That looks like a build problem because it tries to write file somewhere it should not.

                        Did you do that in the Run part only ?

                        P Offline
                        P Offline
                        Please_Help_me_D
                        wrote on 6 Dec 2019, 00:06 last edited by
                        #11

                        @SGaist I'm sorry for disturbing you but don't you know why some of VTK examples work and other doesn't?
                        For example I can run ex1(works) and ex2(works) but I can't launch ex3(not_work)
                        The output from my app is:
                        03:02:26: Strart C:\Users\Tasik\Documents\Qt_prj\build-untitled-Desktop_Qt_5_12_5_MSVC2017_64bit-Release\release\untitled.exe ...
                        03:02:26: Application unexpectly stopped.
                        03:02:26: The process was forced to stop.
                        03:02:26: C:/Users/Tasik/Documents/Qt_prj/build-untitled-Desktop_Qt_5_12_5_MSVC2017_64bit-Release/release/untitled.exe crashed.

                        1 Reply Last reply
                        0
                        • S Offline
                          S Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on 6 Dec 2019, 22:02 last edited by
                          #12

                          Do you have the same issue in Debug mode ?

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          P 1 Reply Last reply 7 Dec 2019, 09:04
                          0
                          • S SGaist
                            6 Dec 2019, 22:02

                            Do you have the same issue in Debug mode ?

                            P Offline
                            P Offline
                            Please_Help_me_D
                            wrote on 7 Dec 2019, 09:04 last edited by
                            #13

                            @SGaist yes, the behavior is the same in release and debug mode

                            1 Reply Last reply
                            0
                            • S Offline
                              S Offline
                              SGaist
                              Lifetime Qt Champion
                              wrote on 7 Dec 2019, 21:27 last edited by
                              #14

                              In that case, run your application using the debugger. It will allow you to gather more information on what is going on.

                              Interested in AI ? www.idiap.ch
                              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                              P 1 Reply Last reply 8 Dec 2019, 01:07
                              0
                              • S SGaist
                                7 Dec 2019, 21:27

                                In that case, run your application using the debugger. It will allow you to gather more information on what is going on.

                                P Offline
                                P Offline
                                Please_Help_me_D
                                wrote on 8 Dec 2019, 01:07 last edited by
                                #15

                                @SGaist I can't put a "break point" beacause in this case I get the error: "cdb stopped".
                                If I just run app in debug mode I get the application output:

                                04:05:17: C: \ Users \ Tasik \ Documents \ Qt_prj \ build-VTK-Desktop_Qt_5_12_5_MSVC2017_64bit-Debug \ debug \ VTK.exe starts ...
                                04:05:17: The program ended unexpectedly.
                                04:05:17: The process was completed forcibly.
                                04:05:17: C: /Users/Tasik/Documents/Qt_prj/build-VTK-Desktop_Qt_5_12_5_MSVC2017_64bit-Debug/debug/VTK.exe failed.
                                

                                and compiler output:

                                04:05:17: Steps are being carried out for the VTK project ...
                                04:05:17: Settings have not changed, the qmake stage is skipped.
                                04:05:17: It starts: "C: \ Qt \ Tools \ qtcreator-4.10.2 \ bin \ jom.exe"
                                C: \ Qt \ Tools \ qtcreator-4.10.2 \ bin \ jom.exe -f Makefile.Debug
                                04:05:17: The process "C: \ Qt \ Tools \ qtcreator-4.10.2 \ bin \ jom.exe" completed successfully.
                                04:05:17: Elapsed time: 00:00.
                                
                                1 Reply Last reply
                                0
                                • S Offline
                                  S Offline
                                  SGaist
                                  Lifetime Qt Champion
                                  wrote on 8 Dec 2019, 20:18 last edited by
                                  #16

                                  How did you install the debugger ?

                                  Interested in AI ? www.idiap.ch
                                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                  P 1 Reply Last reply 8 Dec 2019, 23:56
                                  0
                                  • S SGaist
                                    8 Dec 2019, 20:18

                                    How did you install the debugger ?

                                    P Offline
                                    P Offline
                                    Please_Help_me_D
                                    wrote on 8 Dec 2019, 23:56 last edited by
                                    #17

                                    @SGaist I don't know exactly but I think it was installed with Visual Studio 2017. Isn'it?

                                    J 1 Reply Last reply 9 Dec 2019, 05:28
                                    0
                                    • P Please_Help_me_D
                                      8 Dec 2019, 23:56

                                      @SGaist I don't know exactly but I think it was installed with Visual Studio 2017. Isn'it?

                                      J Offline
                                      J Offline
                                      jsulm
                                      Lifetime Qt Champion
                                      wrote on 9 Dec 2019, 05:28 last edited by
                                      #18

                                      @Please_Help_me_D said in Add VTK library to Qt project:

                                      Isn'it?

                                      No, the debugger in Visual Studio can't be used outside of Visual Studio.
                                      You need to install Debugging Tools for Windows/CDB.
                                      See https://doc.qt.io/qtcreator/creator-debugger-engines.html

                                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                                      P 1 Reply Last reply 9 Dec 2019, 15:55
                                      0
                                      • J jsulm
                                        9 Dec 2019, 05:28

                                        @Please_Help_me_D said in Add VTK library to Qt project:

                                        Isn'it?

                                        No, the debugger in Visual Studio can't be used outside of Visual Studio.
                                        You need to install Debugging Tools for Windows/CDB.
                                        See https://doc.qt.io/qtcreator/creator-debugger-engines.html

                                        P Offline
                                        P Offline
                                        Please_Help_me_D
                                        wrote on 9 Dec 2019, 15:55 last edited by
                                        #19

                                        @jsulm thank you
                                        My debugger is in folder: C:\Program Files (x86)\Windows Kits\10\Debuggers\x64\cdb.exe
                                        Then I don't know how it was installed. It was already installed by the time when I installed Qt. Should I install some new debugger?
                                        By the way in most application I can set a breakpoint and work with debugger. But in this case it doesn't work.

                                        1 Reply Last reply
                                        0
                                        • P Offline
                                          P Offline
                                          Please_Help_me_D
                                          wrote on 9 Dec 2019, 16:20 last edited by
                                          #20

                                          I set up CDB path as it said in link text but still doesn't work.
                                          Am I right that if my CDB installed properly then it should run my app and if some problem occurs then an error should appear that more detailed describes my problem?

                                          1 Reply Last reply
                                          0

                                          8/42

                                          3 Dec 2019, 19:41

                                          topic:navigator.unread, 34
                                          • Login

                                          • Login or register to search.
                                          8 out of 42
                                          • First post
                                            8/42
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved