<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.slicer.org/w/index.php?action=history&amp;feed=atom&amp;title=Documentation%2F4.4%2FDevelopers%2FTutorials%2FCreateLoadableModule</id>
	<title>Documentation/4.4/Developers/Tutorials/CreateLoadableModule - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://www.slicer.org/w/index.php?action=history&amp;feed=atom&amp;title=Documentation%2F4.4%2FDevelopers%2FTutorials%2FCreateLoadableModule"/>
	<link rel="alternate" type="text/html" href="https://www.slicer.org/w/index.php?title=Documentation/4.4/Developers/Tutorials/CreateLoadableModule&amp;action=history"/>
	<updated>2026-05-06T05:21:03Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.33.0</generator>
	<entry>
		<id>https://www.slicer.org/w/index.php?title=Documentation/4.4/Developers/Tutorials/CreateLoadableModule&amp;diff=40243&amp;oldid=prev</id>
		<title>UpdateBot: Nightly -&gt; 4.4</title>
		<link rel="alternate" type="text/html" href="https://www.slicer.org/w/index.php?title=Documentation/4.4/Developers/Tutorials/CreateLoadableModule&amp;diff=40243&amp;oldid=prev"/>
		<updated>2014-12-25T06:45:28Z</updated>

		<summary type="html">&lt;p&gt;Nightly -&amp;gt; 4.4&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;noinclude&amp;gt;{{documentation/versioncheck}}&amp;lt;/noinclude&amp;gt;&lt;br /&gt;
=Consider also reading=&lt;br /&gt;
*[[Media:QtPortInSlicer.ppt|QtPortInSlicer - How to write a module]]&lt;br /&gt;
*[[Documentation/{{documentation/version}}/Developers/Tutorials/ExternalModuleWriting|How to write an external module]]&lt;br /&gt;
&lt;br /&gt;
= Initialization =&lt;br /&gt;
=== 1) Create the module directory ===&lt;br /&gt;
&lt;br /&gt;
Use the [[Documentation/{{documentation/version}}/Developers/ExtensionWizard|extension wizard]] to generate files and directory based on a template.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
{|&lt;br /&gt;
! style=&amp;quot;border-bottom: 1px solid darkgrey;&amp;quot;| &amp;lt;small&amp;gt;Linux&amp;lt;/small&amp;gt;&lt;br /&gt;
! style=&amp;quot;border-bottom: 1px solid darkgrey;&amp;quot;| &amp;lt;small&amp;gt;Mac&amp;lt;/small&amp;gt;&lt;br /&gt;
! style=&amp;quot;border-bottom: 1px solid darkgrey;&amp;quot;| &amp;lt;small&amp;gt;Windows&amp;lt;/small&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| colspan=2; valign=&amp;quot;top&amp;quot; |&lt;br /&gt;
Start terminal (&amp;lt;code&amp;gt;bash&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;Terminal.app&amp;lt;/code&amp;gt;), then type the following:&amp;lt;br&amp;gt;&lt;br /&gt;
 $ cd /path/to/Slicer4&lt;br /&gt;
 $ python Utilities/Scripts/ModuleWizard.py MY_MODULE_NAME&lt;br /&gt;
| valign=&amp;quot;top&amp;quot; |&lt;br /&gt;
Start &amp;lt;code&amp;gt;cmd.exe&amp;lt;/code&amp;gt; terminal, then type the following (in 64-bit mode replace &amp;lt;code&amp;gt;PCbuild&amp;lt;/code&amp;gt; with &amp;lt;code&amp;gt;PCbuild\amd64&amp;lt;/code&amp;gt;):&amp;lt;br&amp;gt;&lt;br /&gt;
 $ cd C:\path\to\Slicer4&lt;br /&gt;
 $ ..\Slicer4-Superbuild\python-build\PCBuild\python.exe Utilities\Scripts\ModuleWizard.py MY_MODULE_NAME&lt;br /&gt;
|}&lt;br /&gt;
Replace &amp;lt;code&amp;gt;MY_MODULE_NAME&amp;lt;/code&amp;gt; with the name of the module you want (e.g. &amp;lt;code&amp;gt;HelloWorld&amp;lt;/code&amp;gt;)&amp;lt;br&amp;gt;&lt;br /&gt;
After running the script, a new directory &amp;lt;code&amp;gt;MY_MODULE_NAME&amp;lt;/code&amp;gt; will be created in &amp;lt;code&amp;gt;Slicer4/Modules/Loadable&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 2) Build ===&lt;br /&gt;
&lt;br /&gt;
See [[Documentation/Nightly/Developers/ExtensionWizard#Building]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== 3) Install ===&lt;br /&gt;
&lt;br /&gt;
See [[Documentation/Nightly/Developers/ExtensionWizard#.22Installation.22]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
=== 2) Add the module in CMake ===&lt;br /&gt;
Edit the file [http://viewvc.slicer.org/viewvc.cgi/Slicer4/trunk/Modules/Loadable/CMakeLists.txt?view=markup Slicer4/Modules/Loadable/CMakeLists.txt]:&lt;br /&gt;
Add the name of your module at the end of the qtmodules variable assignment:&lt;br /&gt;
 ...&lt;br /&gt;
 set(qtmodules&lt;br /&gt;
   ...&lt;br /&gt;
   MY_MODULE_NAME&lt;br /&gt;
   )&lt;br /&gt;
 ...&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
=== 3) Compile ===&lt;br /&gt;
Compile the inner build (''Slicer-build'' inside the Superbuild directory).&lt;br /&gt;
{|&lt;br /&gt;
! style=&amp;quot;border-bottom: 1px solid darkgrey;&amp;quot;| &amp;lt;small&amp;gt;Linux&amp;lt;/small&amp;gt;&lt;br /&gt;
! style=&amp;quot;border-bottom: 1px solid darkgrey;&amp;quot;| &amp;lt;small&amp;gt;Mac&amp;lt;/small&amp;gt;&lt;br /&gt;
! style=&amp;quot;border-bottom: 1px solid darkgrey;&amp;quot;| &amp;lt;small&amp;gt;Windows&amp;lt;/small&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| colspan=2; valign=&amp;quot;top&amp;quot; |&lt;br /&gt;
 $ cd ../Slicer4-Superbuild/Slicer-build;&lt;br /&gt;
 $ make -j4&lt;br /&gt;
| valign=&amp;quot;top&amp;quot; |&lt;br /&gt;
 $ cd ..\Slicer4-Superbuild\Slicer-build;&lt;br /&gt;
 $ .\Slicer.exe --VisualStudio Slicer.sln&lt;br /&gt;
In Visual Studio, go to Build -&amp;gt; Build Solution&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 4) Check the module ===&lt;br /&gt;
Start Slicer and make sure the module is present (listed under &amp;quot;Module Template&amp;quot;)&lt;br /&gt;
 $ ./Slicer&lt;br /&gt;
To change the module title that shows up in Slicer, edit the file &amp;lt;code&amp;gt;Slicer4/Modules/Loadable/MY_MODULE_NAME/CMakeLists.txt&amp;lt;/code&amp;gt; &lt;br /&gt;
 set(MODULE_TITLE &amp;quot;Your title&amp;quot;) &lt;br /&gt;
Other [http://slicer.org/doc/html/classqSlicerAbstractCoreModule.html#properties properties] for the module such as '''help''', '''acknowledgment''' or '''categories''' can be re-implemented directly in C++ by editing &amp;lt;code&amp;gt;Slicer4/Modules/Loadable/MY_MODULE_NAME/qSlicerMY_MODULE_NAME.cxx&amp;lt;/code&amp;gt;. &lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 5) Open Qt Designer using the launcher ===&lt;br /&gt;
''Slicer'' (the launcher) searches Qt Designer on your machine (using &amp;lt;code&amp;gt;QT_QMAKE_EXECUTABLE&amp;lt;/code&amp;gt; set at configure time). It starts the designer after setting the correct environment variables (&amp;lt;code&amp;gt;QT_PLUGIN_PATH&amp;lt;/code&amp;gt; for the widgets designer plugins and PATH/LD_LIBRARY_PATH for the libraries).&lt;br /&gt;
 $ ./Slicer --designer&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 6) Change the UI ===&lt;br /&gt;
Using Qt Designer, edit the module UI file: &amp;lt;code&amp;gt;Modules/Loadable/MY_MODULE_NAME/Resources/UI/qSlicerMY_MODULE_NAMEModule.ui&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
[[Documentation/{{documentation/version}}/Developers/Tutorials/QtDesigner|More info on how to use the designer]]&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 7) Edit the module files ===&lt;br /&gt;
 Slicer4/Modules/Loadable/MY_MODULE_NAME/qSlicerMY_MODULE_NAME.[h|cxx]&lt;br /&gt;
 Slicer4/Modules/Loadable/MY_MODULE_NAME/qSlicerMY_MODULE_NAMEWidget.[h|cxx]&lt;br /&gt;
 Slicer4/Modules/Loadable/MY_MODULE_NAME/Logic/vtkSlicerMY_MODULE_NAMELogic.[h|cxx]&lt;br /&gt;
 ...&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Qt Designer =&lt;br /&gt;
* How to set icons to widgets&lt;br /&gt;
** In the icon property entry of the widget (Property Editor), select a resource file&lt;br /&gt;
*** Slicer4/Modules/Loadable/MY_MODULE_NAME/Resources/qSlicerMY_MODULE_NAMEModule.qrc&lt;br /&gt;
*** Slicer4/Libs/MRML/Widgets/Resources/qMRMLWidget.qrc&lt;br /&gt;
*** Slicer4/Base/QTGUI/Resources/qSlicerBaseQTGUI.qrc&lt;br /&gt;
* How to add an icon in a resource file&lt;br /&gt;
** Add the icon in Slicer4/Modules/Loadable/MY_MODULE_NAME/Resources/Icon&lt;br /&gt;
** Edit the resource file by adding the line&lt;br /&gt;
*** &amp;quot;&amp;lt;file&amp;gt;Icons/MyIcon.png&amp;lt;/file&amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
= Dependency between modules =&lt;br /&gt;
It is possible that your module needs to access information from another module. Typically the logic or the custom MRML classes of a module.&lt;br /&gt;
The following code is an example of what can be done to make your module dependent to the Volumes module logic:&lt;br /&gt;
&lt;br /&gt;
In CMakeLists.txt:&lt;br /&gt;
  set(MODULE_INCLUDE_DIRECTORIES&lt;br /&gt;
    ${CMAKE_CURRENT_SOURCE_DIR}/Widgets&lt;br /&gt;
    ${CMAKE_CURRENT_BINARY_DIR}/Widgets&lt;br /&gt;
    ${vtkSlicerVolumesModuleLogic_SOURCE_DIR}&lt;br /&gt;
    ${vtkSlicerVolumesModuleLogic_BINARY_DIR}&lt;br /&gt;
    )&lt;br /&gt;
   ... &lt;br /&gt;
  set(MODULE_TARGET_LIBRARIES&lt;br /&gt;
    ...&lt;br /&gt;
    vtkSlicerVolumesModuleLogic&lt;br /&gt;
    )&lt;br /&gt;
&lt;br /&gt;
In qSlicerMY_MODULE_NAMEModule.cxx:&lt;br /&gt;
  &lt;br /&gt;
  //-----------------------------------------------------------------------------&lt;br /&gt;
  QStringList qSlicerMY_MODULE_NAMEModule::dependencies()const&lt;br /&gt;
  {&lt;br /&gt;
    return QStringList() &amp;lt;&amp;lt; &amp;quot;Volumes&amp;quot;;&lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
  //-----------------------------------------------------------------------------&lt;br /&gt;
  void qSlicerMY_MODULE_NAMEModule::setup()&lt;br /&gt;
  {&lt;br /&gt;
    this-&amp;gt;Superclass::setup();&lt;br /&gt;
 &lt;br /&gt;
    vtkSlicerMY_MODULE_NAMELogic* moduleLogic =&lt;br /&gt;
      vtkSlicerMY_MODULE_NAMELogic::SafeDownCast(this-&amp;gt;logic());&lt;br /&gt;
 &lt;br /&gt;
    qSlicerAbstractCoreModule* volumesModule =&lt;br /&gt;
      qSlicerCoreApplication::application()-&amp;gt;moduleManager()-&amp;gt;module(&amp;quot;Volumes&amp;quot;);&lt;br /&gt;
    if (volumesModule)&lt;br /&gt;
      {&lt;br /&gt;
      vtkSlicerVolumesLogic* volumesLogic = &lt;br /&gt;
        vtkSlicerVolumesLogic::SafeDownCast(volumesModule-&amp;gt;logic());&lt;br /&gt;
      moduleLogic-&amp;gt;SetVolumesLogic(volumesLogic);&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
By specifying the module as a dependency, you are insured that the dependency module will be setup before your module is setup.&lt;br /&gt;
&lt;br /&gt;
Follow the same pattern in CMakeLists.txt to add dependency on a module widgets:&lt;br /&gt;
&lt;br /&gt;
 set(MODULE_INCLUDE_DIRECTORIES&lt;br /&gt;
   ... &lt;br /&gt;
   ${qSlicerVolumesModuleWidgets_SOURCE_DIR}&lt;br /&gt;
   ${qSlicerVolumesModuleWidgets_BINARY_DIR}&lt;br /&gt;
   ...&lt;br /&gt;
   )&lt;br /&gt;
  ...&lt;br /&gt;
  set(MODULE_TARGET_LIBRARIES&lt;br /&gt;
    ...&lt;br /&gt;
    qSlicerVolumesModuleWidgets&lt;br /&gt;
    )&lt;br /&gt;
&lt;br /&gt;
It works the same if you want to access the custom MRML (''vtkSlicerDEPENDENT_MODULEModuleMRML_SOURCE_DIR'') or displayable manager (''vtkSlicerDEPENDENT_MODULEModuleDisplayableManager_SOURCE_DIR'') classes.&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
# [[Documentation/{{documentation/version}}/Modules/CropVolume|Crop Volume]] module [http://viewvc.slicer.org/viewvc.cgi/Slicer4/trunk/Modules/Loadable/CropVolume/qSlicerCropVolumeModule.cxx?view=markup depends] on [[Documentation/{{documentation/version}}/Modules/Volumes|Volumes]] module&lt;/div&gt;</summary>
		<author><name>UpdateBot</name></author>
		
	</entry>
</feed>