Documentation/4.6/Developers/QtPlugins

From Slicer Wiki
Revision as of 06:49, 7 November 2016 by UpdateBot (talk | contribs) (Nightly -> 4.6)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Home < Documentation < 4.6 < Developers < QtPlugins


For the latest Slicer documentation, visit the read-the-docs.


Qt Plugins

Plugins for Qt (e.g. designer, iconengines, image formats) are automatically discovered and loaded by Qt based on the directory plugins are into. There are multiple ways to tell Qt where to scan directories containing plugins. addLibraryPath would probably be the easiest, but because plugins (e.g. designer) must be localized by Qt Designer when designing UIs, the solution is to have the environment variable QT_PLUGIN_PATH set by the Slicer launcher (or using a qt.conf file when no launcher is available (e.g. MacOsX Slicer installs)). A limitation of qt.conf is that it only handles 1 plugin path, this is why Slicer installs must have their plugins in a unique top directory.

Configuration

To create a plugin, use one of the macros in ctkMacroBuildQtPlugin.cmake:

  • ctkMacroBuildQtDesignerPlugin to build a Qt Designer plugin.
  • ctkMacroBuildQtIconEnginesPlugin to build an Icon Engine plugin.
  • ...

They are built in the bin/PLUGIN_TYPE directory where PLUGIN_TYPE is designer, imageformats... Only on Visual Studio they are also automatically in XXX-build/bin/PLUGIN_TYPE/BUILD_TYPE where BUILD_TYPE is Debug, Release... Refer to

Mac Bundle

Because Qt plugins are not direct dependency of Slicer (discovered and dynamically loaded at run time), Qt plugins need to be compiled as MODULE and need to be manually bundled at package time (see SlicerCompleteBundles.cmake.in).

Build

QT_PLUGIN_PATH must points to 2 paths: Slicer-Superbuild/CTK-build/CTK-build/bin and Slicer_QtPlugins_DIR=Slicer-Superbuild/Slicer-build/bin.

The default Qt plugins (such as svg image format or sqldriver plugins) are in the Qtdir plugin path.

Plugins locations for Slicer builds:

  • Slicer-Superbuild/CTK-build/CTK-build/bin/designer/CTK??????WidgetsPlugins.{so|dll}
  • Slicer-Superbuild/Slicer-build/bin/designer/qSlicer??????WidgetsPlugins.{so|dll}
  • Slicer-Superbuild/Slicer-build/bin/iconengines/qSlicer??????Plugin.{so|dll}
  • QtDir/plugins/imageformats/*.{so|dll|dylib}

On Windows, they also are in the following paths but are ignored by Qt:

  • Slicer-Superbuild/CTK-build/CTK-build/bin/designer/Release/CTK??????WidgetsPlugins.{so|dll}
  • Slicer-Superbuild/Slicer-build/bin/designer/Release/qSlicer??????WidgetsPlugins.{so|dll}
  • Slicer-Superbuild/Slicer-build/bin/iconengines/Release/qSlicer??????Plugin.{so|dll}

See Build directory structure

Install

QT_PLUGIN_PATH points to a unique path: Slicer_INSTALL_QtPlugins_DIR=Slicer/lib/QtPlugins. However, on MacOSX, there is no launcher, so environment variables can't be set prior to launching Slicer. A qt.conf containing the Slicer/lib/QtPlugins path is used for the mac bundle. In order for the plugins to be installed at the right location, CTK_INSTALL_QTPLUGIN_DIR must be passed to CTK (see External_CTK.cmake, this is internally used by ctkMacroBuildQtPlugin.cmake) Because Qt is packaged within Slicer, the plugins must also be packaged (see SlicerBlockInstallQtPlugins.cmake) Plugins locations for installed Slicer:

  • Slicer/lib/QtPlugins/designer/CTK??????WidgetsPlugins.{so|dll}
  • Slicer/lib/QtPlugins/iconengines/qSlicer??????WidgetsPlugins.{so|dll}
  • Slicer/lib/QtPlugins/imageformats/*.{so|dll|dylib}
  • Slicer/lib/QtPlugins/sqldrivers/*.{so|dll|dylib}

See Install directory structure

Extensions

Extensions need to provide their plugin paths to the Slicer launcher.