我正在尝试在 Qt6 应用程序中使用 VTK。我已经成功地在 Qt5 应用程序中使用它,但想迁移到 Qt6。
我使用的是 MacOS Ventura (13.2.1)。我已经通过 Qt Creator 安装了 Qt5.15.2 和 Qt6.4.2。两者都工作正常。
但是,当我尝试与 VTK(9.2,通过自制程序安装)结合时,它似乎只能与 Qt5 配合使用。如果我将
find_package(VTK 9.2 REQUIRED)
添加到我的 CMakeLists.txt
,然后尝试使用 Qt6 编译应用程序,我会收到以下错误:
CMake Error at /usr/local/lib/cmake/vtk-9.2/VTK-vtk-module-find-packages.cmake:115 (find_package):
By not providing "FindQt5.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "Qt5", but
CMake did not find one.
Could not find a package configuration file provided by "Qt5" (requested
version 5.15) with any of the following names:
Qt5Config.cmake
qt5-config.cmake
Add the installation prefix of "Qt5" to CMAKE_PREFIX_PATH or set "Qt5_DIR"
to a directory containing one of the above files. If "Qt5" provides a
separate development package or SDK, be sure it has been installed.
Call Stack (most recent call first):
/usr/local/lib/cmake/vtk-9.2/vtk-config.cmake:155 (include)
CMakeLists.txt:22 (find_package)
所以它似乎想要引用 Qt5,尽管如果我正在构建 Qt6 应用程序,那应该不是必需的,对吗?查看
VTK-vtk-module-find-packages.cmake
文件,第 115 行显示:
find_package(Qt5
5.15
所以我的 VTK 安装中似乎有一些对 Qt5 的硬编码引用。我在安装VTK的过程中做错了什么吗? (我刚刚输入了
brew install vtk
)或者Qt6还不支持?根据 this thread,从 VTK 9.1 开始应包含支持。但他们谈论在 VTK CMake 过程中配置它。我怎么做?使用自制程序可能无法实现这一点吗?
如果brew不提供针对Qt6构建的版本,您需要自己构建VTK来链接Qt6。
vcpkg 例如提供针对 Qt6 的 VTK 构建。
截至 2023 年 8 月 1 日,brew 的 VTK 软件包已切换到 Qt6。那么这个问题就不再是问题了。
此外,VTK8也已被禁用。因此,截至 2023 年 8 月,Homebrew 中不再有仍具有 Qt5 依赖项的 VTK 包。不幸的是,这会产生相反的问题 - 现有的 Qt5 程序在移植到 Qt6 之前无法再构建。目前,通过 MacPorts 使用 Qt5 从源代码构建 VTK 是一种解决方法。