Which Qt and VTK for QVTKOpenGLWidget?

In an attempt to avoid the segfault I’m getting with QVTKWidget (Qt-4.8, VTK-5.10) I am planning to upgrade to a version of VTK that includes QVTKOpenGLWidget. In which VTK version did this widget first appear? Will I need a later version of Qt as well? If possible I’d like to avoid having to make many code changes.


1 Like

The first version of VTK containing QVTKOpenGLWidget is VTK 8.0.0
However, it has been reworked deeply recently, so I would suggest going for the next release this year, once it’s out.

Thanks Mathieu,
To get up to speed, I have installed Qt5, and built VTK-8.2.0 with Qt GUI support. To start with I am leaving my code as is, i.e. still using QVTKWidget. After many adjustments (to account for the changes from old versions of Qt and VTK) I am almost building my program (in Qt Creator). Now I just get one linking error:

/usr/local/lib/vtk-8.2/libvtkGUISupportQt-8.2.a(QVTKWidget.cxx.o):-1: In function QVTKWidget::SetRenderWindow(vtkRenderWindow*)': QVTKWidget.cxx:-1: error: undefined reference toQX11Info::display()’

Does this convey anything to you? Does it mean QVTKWidget is not just deprecated, it is also invalid?


It is not invalid. looks like you are missing a link to x11extras, could you add it to see if this fixes it ?

Hi Mathieu,
Sorry to be so late in replying - got distracted onto other things.
Yes, adding that library fixes the link error.

The link is successful, but the program crashes while setting up a QVTKWidget. Here is the code, up to the call where the crash occurs:

MyVTK::MyVTK(QWidget *page, QWidget *key_page)
zoomlevel = 0.7; //0.25
double backgroundColor[] = {0.0,0.0,0.0};
page_VTK = page;
Global::leftb = false;
qvtkWidget = new QVTKWidget(page_VTK,QFlag(0));
QVBoxLayout *layout = new QVBoxLayout;
// Associate the layout with page_VTK
// Create a renderer, and add it to qvtkWidget’s render window.
// The renderer renders into the render window.
ren = vtkRenderer::New();
renWin = qvtkWidget->GetRenderWindow();

This works in VTK 6.3 with Qt 4.8. What am I doing wrong?
This is on Ubuntu 16.04.

Please refer to QVTKWidget examples.
eg: VTK/Examples/GUI/Qt/ImageViewer

I see that this example uses QVTKOpenGLWidget. Does that imply that although QVTKWidget is still in VTK 8.2, it is not usable?

Sorry, about that. I forgot the example got updated.

VTK/Examples/GUI/Qt/Events still uses QVTKWidget.

That example uses setRenderWindow, which is supposed to be a member function of QVTKWidget, e.g. see https://vtk.org/doc/nightly/html/classQVTKWidget.html. But I get the compile error:
class ‘QVTKWidget’ has no member named ‘setRenderWindow’
Presumably there have been some changes to QVTKWidget by version 8.2. This raises the question: is QVTKWidget usable with VTK 8.2? setRenderWindow no longer exists, and getRenderWindow doesn’t give a compile error but causes my program to crash.

Hi Mathieu,
The compile error is with my own program. I haven’t managed to get to the build stage yet with the Events example, because when I run cmake I get this error:

CMake Error at CMakeLists.txt:46 (add_executable):
Target “qtevents” links to target “Qt5::X11Extras” but the target was not found. Perhaps a find_package() call is missing for an IMPORTED target, or an ALIAS target is missing?

Based on this info from Marcus Hanwell: https://blog.kitware.com/cmake-finding-qt5-the-right-way/
I tried adding this:

set(Qt5_DIR ~/Qt5.13.0/5.13.0/gcc_64/lib/cmake/Qt5 )
find_package(Qt5 COMPONENTS Core Widgets REQUIRED)

since that directory contains Qt5Config.cmake, but the same error occurs. Do you know what I need to do to ensure that cmake finds X11Extras? The library libQt5X11Extras.so is present with all the other Qt5 libraries.

(I get the same cmake error with the SimpleView example. With the ImageViewer example I get that the vtkTestingCore module is not available - I guess I didn’t build it.)


Edit: If I ignore the cmake error and run make anyway, I get many warnings about QVTKWidget being deprecated, then this link error:
[100%] Linking CXX executable qtevents
/usr/bin/ld: cannot find -lQt5::X11Extras
collect2: error: ld returned 1 exit status

Presumably there is a way to tell cmake where to find libQt5X11Extras.so, but it seems to be looking for a different name - libQt5::X11Extras.so. I don’t know how to treat that ‘Qt5::’.

I discovered that the build was not using the Qt installation that I intended, which led to the discovery that I hadn’t built VTK-8.2 with Qt-5.13.0 (an earlier Qt installation was being used). Rebuilding VTK-8.2 with the right Qt fixed the example build problem (after I added X11Extras to the find-package list) - the Events example now works. I still have to sort out my own program

I’ve given up on getting QVTKWidget to work in my program on Linux. I’ve tried with both Qt4-VTK5 and Qt5-VTK8, getRenderWindow() causes the program to crash and I can’t see why. I’m going to explore using Qt’s own 3D capabilities.

The first version of VTK containing QVTKOpenGLWidget is VTK 8.0.0
However, it has been reworked deeply recently, so I would suggest going for the next release this year, once it’s out.

Hi @mwestphal

So, ParaView 5.4.1 (the one that can be installed with a package manager in Centos 7 or Ubuntu) is not using VTK 7.1.1 (I thought it was using that version of VTK) ?

@cory.quammen already answered you there, but for completeness, ParaView is not using a release of VTK, but a specific hash, which is a9b132548dc19b8e20898b424b31cafacbf39246 for ParaView 5.4.1.

1 Like

Hi, FYI, I just was able to get QVTKOpenGLNativeWidget running together with vtkGenericOpenGLRenderWindow and QVTKInteractor on linux with 9.0.0.rc2
and Qt 5.14.1 (from openSUSE tumbleweed system package).

One weird thing is that I had to set
vtkGenericOpenGLRenderWindow::SetGlobalMaximumNumberOfMultiSamples(0), sometimes
resulting in strange antialiasing. Without that, rendering was basically impossible.