How to get VTK9 + Qt6 working together?

I managed to get VTK9 to compile and work with Qt 5.15.2. But my goal is to use Qt6 which was released earlier this month. Key questions are:

  1. Can I modify CMake variables (like Qt5_DIR, etc.) and get it to work with Qt6? [Currently VTK-CMake complains about expecting Qt5 version].
  2. Will QVTKOpenGLNativeWidget work with Qt6?

Thanks and Happy New Year!

2 Likes

CMake changes are needed to work with Qt6. I believe @sankhesh is investigating Qt6, but hasn’t gotten to VTK yet (he started with CMake itself). I do not know what kinds of changes will be necessary, but QVTKOpenGLNativeWidget is notoriously touchy to internal Qt changes (@mwestphal for that).

I have a WIP branch for vtk here: https://gitlab.kitware.com/vtk/vtk/-/merge_requests/7483

Please feel free to test it and report issues.

2 Likes

Thanks @sankhesh for the quick response. Will check it out.
Sekar

And @utkarshayachit as well.

@sankhesh got it to working (barely), locally of course, after these fixes in the CMake Configure phase (Mac OS 10.14.6 Mojave, Clang 10.0.1):

  • Update git tag -a 9.0.1 -m "my msg" – could have been a bad local tag.
  • I had to hand-update Qt6XYZ_DIR variables for say, 5 out of 7 or so (so I had to Configure five times just for these variables).
  • Replace Qt5 with Qt6 in GUISupport/QtSql/CMakeLists.txt.
  • Couldn’t get rid of Qt5_DIR errors while building Testing for the above, so disabled build of any VTK test.

That meant I was able to Generate. I had to do these fixes in the make phase:

  • QFontMetricsF::width() has been obsoleted, and so replaced with its equivalent horizontalAdvance() method in Rendering/Qt/vtkQtTreeRingMapper.cxx, .h files.
  • Likewise in Views/Qt/vtkQtListView.h, .cpp, vtkQtTreeView.h, .cpp, replace class QRegExp instance with that of class QRegularExpression, and QSortFilterProxyModel::setFilterRegExp() method with its setFilterRegularExpression().
  • We are almost there … Views/Qt/CMakeLists.txt had Qtn:Widgets instead of Qtn::Widgets in its module link command!

Voila! Finally, I was on my way.

So I was able to build VTK9 + Qt6, and run Draw Sphere, the Hello World of VTK, but with a twist. @ben.boeckel was right (not able to mention Mathieu or Utkar): QVTKOpenGLNativeWidget is not positioned properly in the Main Window (always at the left bottom as opposed to where I put it), and the sphere keeps on spinning (should spin only when you click and drag).

If it helps, I am happy to put my little Qt+Vtk project on GitHub and send you the link. Thank you all for responding in the middle of holidays. Happy New Year!!

@NameRakes All those changes exist on my branch that I pointed you to. Use the checkout instructions on the MR to get them. Go to the MR at https://gitlab.kitware.com/vtk/vtk/-/merge_requests/7483 and click the Check out branch button to see the instructions.

Hi @sankhesh, thanks for the response. Yes, I followed the instructions (again today). The output after performing the final step in the MR checkout instructions:

 Merge made by the 'recursive' strategy.
 CMake/vtk-config.cmake.in                 |  5 +++++
 Documentation/release/dev/qt6-support.md  |  6 ++++++
 GUISupport/Qt/CMakeLists.txt              | 29 ++++++++++++++++++++++++-----
 GUISupport/Qt/QFilterTreeProxyModel.cxx   |  4 ++++
 GUISupport/Qt/QVTKInteractor.cxx          |  5 +++++
 GUISupport/Qt/QVTKInteractorAdapter.cxx   |  6 +++---
 GUISupport/Qt/QVTKOpenGLNativeWidget.cxx  |  1 -
 GUISupport/Qt/QVTKOpenGLStereoWidget.cxx  |  1 -
 GUISupport/Qt/QVTKOpenGLWindow.cxx        |  1 -
 GUISupport/Qt/QVTKRenderWindowAdapter.cxx |  3 +--
 GUISupport/Qt/Testing/Cxx/CMakeLists.txt  |  4 ++--
 GUISupport/Qt/vtkQWidgetTexture.cxx       |  8 ++++----
 GUISupport/Qt/vtkQtDebugLeaksView.cxx     |  8 ++++++++
 Rendering/Qt/CMakeLists.txt               |  6 +++---
 Views/Qt/CMakeLists.txt                   |  6 +++---
 15 files changed, 68 insertions(+), 25 deletions(-)

This is exactly the number of changes on the MR page. With this, I had to choose 4 Qt6 directories (Widgets, WidgetsTools, CoreTools, GuiTools) in the CMake Configure phase, and then got this error:

CMake Error at CMake/vtkModule.cmake:4228 (message):
  Could not find the Qt5 external dependency.
Call Stack (most recent call first):
  GUISupport/QtSQL/CMakeLists.txt:11 (vtk_module_find_package)

You can see the hard-coded Qt5:: in the above line, and a single : in another file:

(base) % grep -n Qt5 GUISupport/QtSQL/CMakeLists.txt 
12:  PACKAGE     Qt5
15:  VERSION_VAR         Qt5_VERSION)
16:vtk_module_link(VTK::GUISupportQtSQL PUBLIC Qt5::Sql Qt5::Widgets)

(base) % grep -n ":Widgets" Views/Qt/CMakeLists.txt 
21:vtk_module_link(VTK::ViewsQt PRIVATE Qt${VTK_QT_MAJOR_VERSION}:Widgets)
                                                                ^^^

Full disclaimer: today I haven’t tried to fix these errors, but I expect the result to be the same as yesterday’s exercise (did it twice!). For example, now I grepped for some (not all) of the code lines that didn’t compile yesterday:

(base) % grep -n "fontMetric.width(" Rendering/Qt/vtkQtTreeRingLabelMapper.cxx
366:      if (sdimDC[0] < fontMetric.width(minString))
                                     ^^^
374:      if (sdimDC[1] < fontMetric.width(minString))
411:        delta_x = -(fontMetric.width(testString)) / 2.;
415:        delta_x = -fontMetric.width(testString);

(base) % grep -n QRegExp Views/Qt/vtkQtListView.cxx
163:void vtkQtListView::SetFilterRegExp(const QRegExp& pattern)
                                              ^^^

Today, the downloaded MR git tag looks correct – as I admitted, I had somehow messed up the tag yesterday. I believe all the other necessary changes (over and above the 15 on the MR page) are outlined in my previous response, at least on Mac OS.

If I build it again today, I will post back. Thanks again!

@NameRakes Thanks for testing.

Yes, it is still a work-in-progress (WIP). I haven’t yet added all the changes for RenderingQt, QtSQL and ViewsQt modules. However, GUISupportQt and by extension, QVTKOpenGLNativeWidget should be working fine. Were you able to test that? I’d love to see your results. You’d have to disable the other modules for testing, though.

One more thing - You shouldn’t have to keep merging the branch into master for testing, unless you want to. Just a checkout should do -

git fetch "git@gitlab.kitware.com:sankhesh/vtk.git" "qt6-support"
git checkout -b "sankhesh/vtk-qt6-support" FETCH_HEAD

@sankhesh, yes, initially I stopped with git fetch and git checkout as you point out - but when I saw the errors, I wasn’t sure, so I merged. Yes, I do realize that it is a WIP branch, and appreciate you responding in the middle of the holiday season! :+1:. Also, I am glad to be able to test the WIP branch.

Here is my little test program:

It is QAD program (Quick and Dirty) - the data source, actor etc. don’t have state - I just put them all into one SLOT function. Let me know if my connectivity part needs any fixes.

@NameRakes, I see that you get VTK9 and Qt5.15.2 working. Would it be possible for you to share some code? It would be great. I’m trying on my side but could not make it so far.

The Qt6 support branch has been merged into master. VTK supports both Qt5 and Qt6. You can choose the version of Qt to use via the variable VTK_QT_VERSION during the CMake configure step.

1 Like

Thanks for your answer. Today I was able to get it working with vtk 8.2 and Qt 5.15. I was able to display a renderer in a QML. However, it still does not work with vtk9. So something must be changed to work with vtk9 but I do not know what. Would you have a small piece of code that is able to do that: vtk9, Qt5.15, a renderer into QML?

@StephPierret See my GitHub link above your message in this thread. Take the GitHub test, replace Qt6 with Q5.15.2, and also change Qt6 references to Qt5 in CMake files. That’s it.

It works. Many thanks for your help.

While Qt 6 support works well with VTK master (THANKS!), it does not seem to be included in the 9.0.2 release.

Does anyone know, is it planned only for 10.x, or maybe also for 9.0.3?

It should be available in VTK 9.1

1 Like

Qt 6 support was too large to backport, sorry.

1 Like

Thanks, this example helped me a lot