# Converting Slicer Python code to C++

**URL:** <https://discourse.slicer.org/t/converting-slicer-python-code-to-c/13762>\
**Category:** Development\
**Created:** [September 30, 2020, 1:05am UTC](https://discourse.slicer.org/t/converting-slicer-python-code-to-c/13762 "2020-09-30T01:05:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nm19](https://avatars.discourse-cdn.com/v4/letter/n/6bbea6/32.png) [@nm19](https://discourse.slicer.org/u/nm19)\
**Post date:** [September 30, 2020, 1:05am UTC](https://discourse.slicer.org/t/converting-slicer-python-code-to-c/13762/1 "2020-09-30T01:05:43Z")

</div>

Hello,

I was looking into converting some Slicer code from Python to C++, in particular from the slicer.util module the loadVolume method. Is there an already existing header file that does this for the util module? If not, any pointers on how to approach this task?

Thanks!

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [September 30, 2020, 7:33pm UTC](https://discourse.slicer.org/t/converting-slicer-python-code-to-c/13762/2 "2020-09-30T19:33:53Z")

</div>

Converting Python code to C++ isn’t conceptually difficult, but there are a lot of steps involved and it’s typically not worth the effort, particularly for something like loading a volume, where the python code already calls down in to C++, so there’s no efficiency gained.

Of course you can load data using C++ but you will need to study a lot of the internal architecture to learn how. I’d suggest reading the tests to get a sense of what’s required.

---

<div class="post-metadata">

**Author:** ![nm19](https://avatars.discourse-cdn.com/v4/letter/n/6bbea6/32.png) [@nm19](https://discourse.slicer.org/u/nm19)\
**Post date:** [September 30, 2020, 10:58pm UTC](https://discourse.slicer.org/t/converting-slicer-python-code-to-c/13762/3 "2020-09-30T22:58:46Z")

</div>

Thanks for the advice.

The reason for doing so is more so for all of our code being in C++, rather than for efficiency. I’ve taken a closer look at the architecture of the existing code and I think I understand how it works. However, I’m at a loss as to what ‘from slicer import app’ is referring to in the util code.

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [October 1, 2020, 12:44pm UTC](https://discourse.slicer.org/t/converting-slicer-python-code-to-c/13762/4 "2020-10-01T12:44:01Z")

</div>

> [@nm19](#):
>
> from slicer import app

You can find out the types by pasting this code in the python console and then typing `app` and you can see that it’s a `qSlicerApplication`. So you need to include the appropriate headers and link the corresponding libraries to use that class in C++.
