In CMake, how to get the Qt install (include dir, libraries, etc) associated with vtkGUISupportQt?

In CMake, how to get the Qt install (include dir, libraries, etc) associated with vtkGUISupportQt?

Basically, I use a library (PCL) that is based on vtkGUISupportQt.

find_package(PCL 1.7.1 COMPONENTS visualization REQUIRED)
find_package(VTK 7 COMPONENTS vtkCommonCore vtkGUISupportQt REQUIRED)

Now to add a GUI in the project, I need Qt. To avoid problems (runtime crash, …), I actually need the Qt install which was used to build vtkGUISupportQt (Qt::Widgets targets used by VTK to build vtkGUISupportQt): does the VTK find_package allow to retrieve the Qt::Widgets targets used to build vtkGUISupportQt? If yes, how to get them (all targets involved)?

In other words, can I ask VTK: “what is the Qt you used to provide vtkGUISupportQt because I need to used this exact same Qt to build GUI on top of it?”

Note: when I just find_package(Qt REQUIRED) I may end up with Qt::Widgets from Qt6 which will conflict with vtkGUISupportQt (which was built with Qt5 for instance) and trigger this kind of cmake error “CMake Error: The INTERFACE_QT_MAJOR_VERSION property of “Qt5::Core” does not agree with the value of QT_MAJOR_VERSION already determined for”

VTK should be finding Qt itself when this happens…though VTK 7 might not, 9 and newer definitely do. VTK should be providing VTK_QT_VERSION which is 5 or 6 depending on which VTK was built with.

Hello,

I hope I understood you problem right.

Quick answer: you need to link your project against the same Qt that was used to build VTK.

Long answer: if Qt5 was used to build VTK but your project needs Qt6, then you may need to do this in the CMakeLists.txt of your project:

target_link_libraries(myExecutable PRIVATE Qt6::Core Qt6::Widgets ...
                                   PUBLIC PCL::visualization ... )

This alone is not enough. You also need to #include Qt6 stuff :warning:only:warning: in the implementation code (normally the .cpp files of your project) where you don’t use VTK’s Qt5-based widget. In other words, don’t mix in the same .cpp file VTK’s Qt5-based classes and Qt6-based classes.

I hope this helps,

PC