Using VTK in QT using Cmake

Hello,

I’m on Windows 11 and have been really struggling to include VTK into the QT. I am very new to VTK. I have built and installed VTK (via ninja) by enabling the following configurations set using cmake-gui:

  1. VTK_GROUP_Qt set to YES
  2. VTK_QT_VERSION set to 6
  3. -DVTK_MODULE_ENABLE_GUISupprtQt set to YES
  • I have also set QML2_IMPORT_PATH=/path/to/vtk/lib/qml/VTK.9.3 and set QML_IMPORT_PATH=/path/to/vtk/lib/qml/VTK.9.3 into cmd.

Now, I have a Qt project in another directory, whose tree is as follows:

VTK Project
| + build
| | + Desktop_Qt_6_7_2_MSVC2019_64bit-Debug
| - CMakeLists.txt
| - CMakeLists.txt.user
| - main.cpp
| - Main.qml

and my VTK installation directory tree looks like this:

VTKBin
| + bin
| | - vtkcgns-9.3d.dll ... (.dll files)
| + include
| | + vtk-9.3
| | | + Octree ...
| | | - QQuickVTKRenderWindow.h ... (.h files)
| + lib
| | + cmake
| | | + vtk-9.3
| | | | - FindCGNS.cmake ... (.cmake files)
| | + qml
| | | + VTK.9.3
| | | | - plugins.qmltypes
| | | | - qmldir
| | | | - qmlvtkplugin.dll
| | + vtk-9.3
| | - vtkcgns-9.3.lib ... (.lib files)
| + share
| | + licenses
| | + vtk-9.3

In my Qt project, I have added the following to the CmakeLists.txt (VTK_DIR points to /VTKBin/lib/cmake/vtk-9.3)

find_package(VTK REQUIRED)
include(${VTK_USE_FILE})
include_directories("C:/VTKBin/include/vtk-9.3/")
add_subdirectory(${VTK_DIR})

When I want to add the following into the main.cpp in order to setting up Graphics Backend (as explained in official Doxygen page here), I use QQuickVTKRenderWindow::setupGraphicsBackend(); but I get a LNK2019: unresolved external symbol error for it. Please, please help me! (or at least give me a hint of official vtk docs for this!)

Thank you so much in advance,

Regards

Hello,

Adding VTK only is not enough. You need to add Qt libraries as well. Please, take a look at this: Building a QML application | Build with CMake 6.7.2 (qt.io). It has a sample CMakeLists.txt that you can use to properly configure a Qt project with CMake.

best,

PC