From Slicer Wiki
Jump to: navigation, search
Home < Documentation < Labs < Qt5-and-VTK8

This page documents the update of Slicer to use Qt 5.


Because Qt4 is not actively developed (as documented here support ended), we need to work toward supporting Qt5.

Similarly because VTK7 is not actively developed, we need to work toward supporting VTK8 and the OpenGL2 rendering backend.

This page summarizes support status of the various components of Slicer stack and remaining tasks.

List of fixes integrated into VTK

  • VTK 8
    • 2017-08: 3b94273: Fix memory leaks in vtkOpenGLRenderer::DonePick() (Max Smolens)
    • 2017-08: 1b9800b: Fix QVTKOpenGLWidget rendering with disabled interactor (Max Smolens)
    • 2017-08: 056dd9a: Fix picking when using QVTKOpenGLWidget (Max Smolens)
    • 2017-08: ee2ea5d: was missing object base initialization (Ken Martin, Max Smolens)
    • 2017-07: e0c60b1: QVTKOpenGLWidget: Set screen size on render window (Max Smolens)
    • 2017-07: 8a60be1: Fix linking libvtkWrapping with Python wrapping and kits enabled on Mac (Max Smolens)
    • 2017-07: bcce50b: cmake: Fix support for VTK_ENABLE_VTKPYTHON set to OFF (Jean-Christophe Fillion-Robin)
    • 2017-07: d0aed86: cmake/vtkCompilerExtras: Remove "--no-undefined" gcc linker flag (Jean-Christophe Fillion-Robin)
    • 2017-06: 5a4ddec: Respect access specifier of using statements in wrapping (Max Smolens)
    • 2017-05: b684733: ENH: Allow selection of seed points using vtkSeedWidget (Andras Lasso)
    • 2017-05: f86a870: Ensure vtkVariant stream associated with << operator is set back to "dec". (Jean-Christophe Fillion-Robin)
    • 2017-05: Support crosspiling emulator
      • 2017-05: 894acce: cmake: Import VTKCompileTools if CROSSCOMPILING_EMULATOR support is incomplete (Jean-Christophe Fillion-Robin)
      • 2017-05: d0f83df: cmake: Simplify buildsystem introducing VTK_COMPILE_TOOLS_IMPORTED (Jean-Christophe Fillion-Robin)
      • 2017-05: d767f09: cmake: Add support for CMAKE_CROSSCOMPILING_EMULATOR (Jean-Christophe Fillion-Robin)
    • 2017-05: 91ca08b: OpenGL2: Fix undeclared "glXGetProcAddressARB" when building on Centos5 (Jean-Christophe Fillion-Robin)
    • 2016-09: 0ea52cc: fix an OpenGL2 issue impacting slicer and add test (Max Smolens)
  • VTK 7
    • 2016-09: d309ca8: Consider whether volume transform preserves orientation (Max Smolens)
    • 2016-09: 0cd1a32: Fix formatting of VTK_DELETE_FUNCTION (Max Smolens)
    • 2016-08: Volume Rendering: Support large transfer function
      • 2016-08: ea74f88: Adjusted LargeColorTf test to add coverage for scale/bias patch. (Alvaro Sanchez)
      • 2016-08: 5d8e8d5: Added texture width checks in opacity and gradientOpacity tables. (Alvaro Sanchez)
      • 2016-08: ddb5ebc: Fixed gl color scale issue. (Alvaro Sanchez)
      • 2016-07: 813462c: Added a method in RGBTable to check whether certain tex size is supported. (Alvaro Sanchez)
      • 2015-12: 114bc96: Add test for GPU volume rendering with a large color transfer function. (Max Smolens)
      • 2015-12: 634a33b: vtkOpenGLGPUVolumeRayCastMapper: handle when table size increases (Max Smolens)
      • 2015-12: 608d4fb: vtkOpenGLGPUVolumeRayCastMapper: remove unnecessary NULL check before delete (Max Smolens)
      • 2015-12: 18b6e57: vtkOpenGLGPUVolumeRayCastMapper: use existing function to find next power of 2 (Max Smolens)
      • 2015-07: f0eba00: GPU raycast volume rendering now supports textures larger than 1024 (Julien Finet)
    • 2016-07: Fix VTK interaction
      • 2016-06: 9ecc055: Fix variable names in vtkImplicitCylinderWidget test (Max Smolens)
      • 2016-06: e8170ff: Fix multiple definitions of vtkInteractionCallback (Max Smolens)
    • 2016-06: 7602a0e: Make vtkCollection implement iterable in the python wrapping (Hastings Greer)
    • 2016-06: dd87a44: Allow pyvtkObjects to have InvokeEvent called on them with calldata (Hastings Greer)
    • 2016-06: a0eb686: Add #include for offsetof() macro in generated Python wrappers (Max Smolens)
    • 2016-04: bd63a80: Handle case when textDims are NULL (Max Smolens)
    • 2016-04: 5dcad97: vtkTextMapper: fix rendering of empty string (Max Smolens)
    • 2016-04: e646e65: Fix vtkAxisActor2D documentation error (Max Smolens)
    • 2016-04: 4be6351: vtkLegendScaleActor: add Modified() call after updating points (Max Smolens)
    • 2016-03: 7a24b32: Change picking manager to not own objects associated with pickers (Max Smolens)
    • 2016-03: Support building python wrapping with VTK_ENABLE_KITS enabled
      • 2016-02: 540f2c5: python: Add adapter modules when VTK_ENABLE_KITS is ON (Max Smolens)
      • 2016-02: 31b7b0e: python: Update wrapping tool to support multiple hierarchy and hint files (Max Smolens)
      • 2016-02: 1ebfa5b: python: Add wrapping of kits when VTK_ENABLE_KITS is ON (Max Smolens)


To configure Slicer:

cmake -DQt5_DIR:PATH=/home/jcfr/Software/Qt5.9.1/5.9.1/gcc_64/lib/cmake/Qt5 ...  ../Slicer

This will automatically build VTK8 with OpenGL2 backend enabled.


  • Use VS2015 on windows


To Do List

  • Test with Qt5.9.1: Linux Check.svg, macOS UnderConstruction.png, Windows: Check.svg
  • Packaging:
    • Update packaging script SlicerCPackBundleFixup.cmake
  • Fix Slicer test failures:
    • Floating point exceptions ("SIGFPE with code FPE_FLTUND") on Mac (ModelToLabelMapTest, ModelToLabelMapTestLabelValue, N4ITKBiasFieldCorrectionTest).
    • py_LandmarkRegistration crash on exit.
    • py_VolumeRenderingThreeDOnlyLayout on Windows ("Shader object was not initialized, cannot attach it."). This is a similar issue as was fixed in r25239, but resurrected due to the behavior of QVTKOpenGLWidget. The old fix is insufficient.
  • Application errors reported at (more information and screenshots are available there)
    • Whenever an item is selected in the Fiducial/ROI/Ruler tool, the items get duplicated to an certain number of items that I didn’t count.
    • In Volume Rending module, the items of the ‘View’ combobox are no longer checkable.
    • Switching to module ‘SceneViews’ crashes Slicer:
      • Switch to module: “SceneViews”
      • qSlicerSceneViewsModuleWidgetPrivate::setupUi - Capture link not implemented with Qt5
      • qSlicerSceneViewsModuleWidgetPrivate::setupUi - Restore scroll bar position not implemented with Qt5
      • As it says, it has yet to be implemented.
  • Windows: Debug build runs very slowly - can it be improved? Build is very slow too, but the application runs so slowly in debug mode that it is basically unusable (this is a change from previous version that were usable for testing real workflows in debug mode).


As of 2017-08-14, the support for Qt5 and VTK8 has been integrated into the trunk.

Command line arguments to expose webgl and webengine debugging:

./Slicer-build/Slicer --enable-experimental-web-platform-features --enable-unsafe-es3-apis --remote-debugging-port=12117 --use-gl=desktop

To Do List

  • Packaging
    • Update packaging scripts (SlicerBlockInstallQt.cmake, SlicerCPackBundleFixup.cmake)
    • Linux:
      • needed to manually copy shared libraries:
        • libsmime3
        • (glibc mismatch, needed GLIBCXX_3.4.21) should build instead with manylinux
      • like on mac, need to create bin/platfrms and bin/sqldrivers and copy in platforms/ and sqldrivers/
    • Mac:
      • Add libqcocoa.dylib and libqsqlite.dylib to package for mac
        mkdir Slicer-build/bin/
        cp ~/Qt/5.7/clang_64/plugins/sqldrivers/libqsqlite.dylib Slicer-build/bin/
        mkdir Slicer-build/bin/
        cp ~/Qt/5.7/clang_64/plugins/platforms/libqcocoa.dylib Slicer-build/bin/

  • Find and fix layout changes.
  • Test branch build with VTK7+OpenGL backend.

  • Build shows errors in console at start: Proposed fix in - Fixed in r26279 and r26280
    • Failed to obtain reference to 'FileMenu'
      Failed to obtain reference to 'qSlicerAppMainWindow'
      No Data Probe frame - cannot create DataProbe
      Failed to obtain reference to 'qSlicerAppMainWindow'
      Failed to obtain reference to 'FileMenu'

  • Linux/Windows/macOS: fix for `libpng warning: iCCP: known incorrect sRGB profile` - Fixed in r26276



As of 2017-08-07 the relevant branches for testing are:

For VS2015 gotchas, see below.

  • Qt5/VTK8 integration TODO:
    • Properly initialize QVTKOpenGLWidget. Call QSurfaceFormat::setDefaultFormat() before constructing the QApplication instance so that an OpenGL core profile context is requested.
    • Properly initialize QVTKOpenGLWidget for tests. Call QSurfaceFormat::setDefaultFormat() before constructing the QApplication instance so that an OpenGL core profile context is requested. (Slicer, CTK)
    • Enable C++11 for Slicer, extensions, and libraries as appropriate.
    • Set OpenGL2 as default rendering backend.
    • CTK and Slicer QtTesting tests refer to QVTKWidget. Can they be converted to recognize QVTKOpenGLWidget?
    • Merge and update CTK: ("Fix compile error on MSVC with Qt 5.7.1")
    • Merge and update VTK: ("Fix linking libvtkWrapping with Python wrapping and kits enabled on Mac")
    • Merge and update VTK: ("QVTKOpenGLWidget: Set screen size on render window")
    • Fix and update VTK: ("QVTKOpenGLWidget: Picking vtkActor2D fails"). In Slicer one operation this issue affects is picking slice view ROI box handles. Merged in
    • Merge and update VTK: QVTKOpenGLWidget can blit uninitialized framebuffers. On Mac, the bug is evident through visible artifacts when resizing the views. Merged in
    • Clicking on module search result in popup does not open the module. ComboBox does not always show the selected item.
      • qMRMLColorPickerWidgetTest2 on Mac crashes due to changes in QColorDialog in Qt5. CTK should no longer assume the non-native dialog is constructed, i.e. the layouts exist, when ctkColorDialog is instantiated.
    • Fix CTK Qt5 test failures.
    • OpenSSL/DataStore/qRestAPI issues?
    • CTK needs to properly export CTK_USE_QVTKOPENGLWIDGET so that the preprocessor correctly handles #if CTK_USE_QVTKOPENGLWIDGET in its header files. Or, an alternative mechanism could be implemented.
    • Windows/Linux: CPU and GPU Volume Rendering display nothing or are corrupt. GPU Volume Rendering gives OpenGL errors. Disabling multisampling before creating the default surface format fixes this. See
    • Mac: Slice views use only lower-left quarter of widget.
      • Set Qt::AA_EnableHighDpiScaling to enable automatic scaling based on the pixel density of the monitor. This enables High DPI for platforms other than Mac.
      • Call setEnableHiDPI(true) on QVTKOpenGLWidgets.
      • qMRMLSliceWidget: Scale SliceView geometry by its devicePixelRatio() before calling this->SliceController->setSliceViewSize().
      • qMRMLSliceWidget: Observe change in devicePixelRatio (i.e. app dragged to another screen) and recompute slice view size.
    • Volume Rendering transfer functions aren't displayed correctly. (ctkVTKChartView)
    • Fix vtkWindowToImageFilter usage of method deprecated in VTK8.1:
    • Fix Qt deprecation warnings.
    • Address "Policy CMP0020 is not set: Automatically link Qt executables to qtmain target on Windows" warnings.
    • Test branch build with VTK7+OpenGL backend. - Changes integrated into the trunk and tested daily
    • Test branch build with VTK7+OpenGL2 backend.
    • Test branch build with Qt4.
    • Test with Qt5.9.1.
    • Support VS2015 by updating to latest python-cmake-buildsystem. Prerequisite: make pre-compiled OpenSSL available for VS2015/VS2017.
    • Update MultiVolumeExplorer hash for Qt5 support.



  • Original branch:


A first running example described in this commit
  • Superbuild configure command on mac using Qt 5.7 stock downloads
cmake \
  -DQT_QMAKE_EXECUTABLE:FILEPATH=/Users/pieper/Qt/5.7/clang_64/bin/qmake \
  -DCMAKE_PREFIX_PATH:PATH=/Users/pieper/Qt/5.7/clang_64/ \
  -DSlicer_USE_SimpleITK:BOOL=OFF \
  -DSlicer_USE_QtTesting:BOOL=OFF \

Platform Notes

Experimental build on Window:

  • Visual Studio Community 2015
  • Qt 5.7
    • Include QtWebEngine and QtScript during install
    • Select 2015 64 bit install
  • Qt 5.8
    • Use Visual Studio Community 2015 or above. Qt-5.8 does not support QtWebEngine for msvc 2013.

Known Issues

  • Slice viewers do not have the expected size after changing layout

To Do List

All platforms
  • Slicer build system upgrade: To be done UnderConstruction.png
    • Add Slicer_QT_VERSION option that could be set to either 4 or 5 - See what is done in CTK Check.svg
    • Fix qRestAPI to support Qt5 (or turn off Slicer_BUILD_EXTENSIONMANAGER_SUPPORT for testing) Check.svg
    • Update use of QT4_* macros (see below) - See what is done in CTK Check.svg
      • The QT5_ versions of the macros appear to be directly compatible Check.svg
    • Port from QtWebKit to QtWebEngine
      • Update of classes using WebKit to work with WebEngineView (these includes "Extension Manager", "Data Store", "Chart View" and `qMRMLExpandingWebView`).
      • `qSlicerWebWidget` should be improved, moved to CTK and used for all widgets making use of a web view.
    • update PythonQt to the latest Qt version Check.svg
      • Look at updating PythonQt to support QWebEngine
    • Fix differences in plugin loading Check.svg
  • Qt5::Network is now a dependency of Base/QTCore (Networking module in Qt5 has classes like QNetworkProxyFactory that were in Qt4's QtCore module)
  • CTK Python wrapping doesn't expose grabWidget.
  • fix fox `libpng warning: iCCP: known incorrect sRGB profile`

Minimal working release experimental build (no cli, ssl, simpleitk, ...) built on ubuntu 16.04, tested on debian 8

  • needed to manually copy shared libraries:
    • libsmime3
    • (glibc mismatch, needed GLIBCXX_3.4.21) should build instead with manylinux
  • like on mac, need to create bin/platfrms and bin/sqldrivers and copy in platforms/ and sqldrivers/
    • on Mac, QT_NO_OPENSSL is defined, but so is QSslError leading to redefined symbol [1](here).
    • Mac crash in qSlicerUnitsSettingsPanelPrivate::addQuantity, appears to be corrupted model. partly addressed by r25855 , finally resolved r25883. Most expedient solution is probably to disable the units settings panel in the application settings since is not widely used in the application.
    • Add libqcocoa.dylib and libqsqlite.dylib to package for mac
  mkdir Slicer-build/bin/
  cp ~/Qt/5.7/clang_64/plugins/sqldrivers/libqsqlite.dylib Slicer-build/bin/
  mkdir Slicer-build/bin/
  cp ~/Qt/5.7/clang_64/plugins/platforms/libqcocoa.dylib Slicer-build/bin/
  • Workarounds here:

  • qtstyleplugins library needs to be removed or ported to support windows Check.svg
    • add declspec exports/imports
    • create .lib for use in QTGUI
    • support shared/static build?
  • AppLauncher settings need to be update
    • Add to PYTHONPATH: <superbuild>/VTKv7-build/bin/Debug (currently lib not bin) Check.svg
    • Add to PATH: <Qt>/5.7/msvc2013_64/bin
  • Debug build runs very slowly - can it be improved? Build is very slow too, but the application runs so slowly in debug mode that it is basically unusable (this is a change from previous version that were usable for testing real workflows in debug mode).
  • Setting Slicer_USE_SimpleITK to ON in CMake results in compile-time errors.
  • Creating a debug build (MSVC 2013, Qt5.7) creates a compile time error on PythonQt.cpp while building the CTK project with message:
    • Error 1220 error C1128: number of sections exceeded object file format limit: compile with /bigobj 

Example starting point command:

cmake \
  -DQt5_DIR:FILEPATH=c:/Qt/5.7/msvc2013_64/lib/cmake/Qt5 \
  -DSlicer_USE_SimpleITK:BOOL=OFF \
  -DSlicer_USE_QtTesting:BOOL=OFF \
  -DSlicer_BUILD_DataStore:BOOL=OFF \
  -G"Visual Studio 12 2013 Win64" \

Migration Guide

This section lists categories of code changes necessary to build and run Slicer with VTK 8.0 and Qt5. Each category has a short description, a suggested upgrade path, and references to relevant commits (TBD once merged).

Qt5: Update loadable modules to use new plugin macros

In Qt5, the Q_EXPORT_PLUGIN, Q_EXPORT_PLUGIN2 macros have been deprecated in favor of the new Q_PLUGIN_METADATA macro.

Error message similar to:

error: static assertion failed: Old plugin system used

Solution (part 1):

Replace lines like:



#ifdef Slicer_HAVE_QT5
  Q_PLUGIN_METADATA(IID "org.slicer.modules.loadable.qSlicerLoadableModule/1.0");

Solution (part 2):

Replace lines like:

Q_EXPORT_PLUGIN2(qSlicer<NameOfModule>Module, qSlicer<NameOfModule>Module);


#include <QtPlugin>
Q_EXPORT_PLUGIN2(qSlicer<NameOfModule>Module, qSlicer<NameOfModule>Module);


Qt5: any use of QWebKit needs to switch to QWebEngine


VTK8: Use hierarchy files for VTK Python wrapping

In VTK8 it's necessary to generate hierarchy files for proper wrapping VTK classes in Python. Without the information provided by the hierarchy files, the Python wrapping tool lacks complete information about classes and types. In this case, the generated classes contain methods that shouldn't be wrapped and fail to compile, and include references to types such as vtkTypeBool. Once the hierarchy files are generated and provided to the Python wrapping tool, the generated classes compile and typedefs like vtkTypeBool are correctly resolved.

Once the VTK8 changes are merged, generating hierarchy files is handled by


VTK8: Use of vtkTypeMacro requires to use the correct base class

Error message similar to:

error: expected unqualified-id before 'protected'

This error is usually a symptom of an incorrect base class when using vtkTypeMacro.


Assuming the class vtkIGTLToMRMLPoint derives from vtkIGTLToMRMLBase,

Replace lines like:





VTK8: Copy constructor and equal operator should be disabled

Error message similar to:

error: use of deleted function 'vtkMyClass::vtkMyClass(const vtkMyClass&)'

This error is usually a symptom of not disabling the copy constructor and equal operator.


Replace lines like:



  vtkMyClass(const vtkMyClass&);
  void operator=(const vtkMyClass&);

VTK8: Call InitializeObjectBase() in vtkObject New() methods

In VTK8 it's necessary for vtkObject New() methods to call InitializeObjectBase() on the new object for proper tracking with vtkDebugLeaks. The standard macros (vtkStandardNewMacro, vtkObjectFactoryNewMacro) handle this. For those classes that don't use the macros, add a call to InitializeObjectBase() immediately after constructing the object by new vtkXXX().

Additionally, vtkObjectFactory::CreateInstance() now doesn't register the class name with vtkDebugLeaks if the factory fails to create the object. Therefore, it's no longer necessary to unregister the class name with vtkDebugLeaks. Remove calls to vtkDebugLeaks::DestructClass(className) following vtkObjectFactory::CreateInstance().

To support both VTK8 and earlier versions of VTK, wrap these changes in preprocessor checks for whether VTK_HAS_INITIALIZE_OBJECT_BASE is defined.


VTK8: Add C++11 keywords

VTK8 requires C++11. Subclasses of VTK classes must mark overridden methods with VTK_OVERRIDE.

Qt5: QVTKOpenGLWidget

When using Qt5, QVTKOpenGLWidget should be used in place of QVTKGLWidget. To ensure that QVTKOpenGLWidget receives a properly configured OpenGL context it's necessary to call QSurfaceFormat::setDefaultFormat() before constructing the QApplication instance. QVTKOpenGLWidget::defaultFormat() supplies a suitable format, although it's recommended to disable multisampling for full compatibility with advanced rendering techniques. See

VTK8: vtkWindowToImageFilter::SetMagnification() is deprecated

VTK8.1 deprecated vtkWindowToImageFilter::SetMagnification() and vtkWindowToImageFilter::GetMagnification(). Replace calls to those methods with SetScale() and GetScale(). See

Enable C++11 in extensions

SuperBuild extensions may have to enable C++11 for their external projects. Add the following lines to CMAKE_CACHE_ARGS in ExternalProject_Add


Qt5: Fix error: 'class QString' has no member named 'toAscii'

Replace call to toAscii().data() with toLatin1().data()


Qt5: Fix error: ‘class QHeaderView’ has no member named ‘setResizeMode’

Error message similar to:

 error: ‘class QHeaderView’ has no member named ‘setResizeMode’
    headerView->setResizeMode(FileColumn, QHeaderView::Stretch);


Replace lines like:

 headerView->setResizeMode(FileColumn, QHeaderView::Stretch);


   headerView->setResizeMode(FileColumn, QHeaderView::Stretch);
   headerView->setSectionResizeMode(FileColumn, QHeaderView::Stretch);

List of extensions that may require updates