Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
QmitkVenvProcess Namespace Reference

Helpers for running an executable from a MITK-managed Python virtual environment as a subprocess. More...

Classes

struct  Result
 

Functions

MITKPYTHONSEGMENTATIONUI_EXPORT QProcessEnvironment CleanEnvironment ()
 The current process environment with PYTHONHOME and PYTHONPATH removed. More...
 
MITKPYTHONSEGMENTATIONUI_EXPORT QString ToQString (const fs::path &path)
 Lossless conversion of a filesystem path to a QString. More...
 
MITKPYTHONSEGMENTATIONUI_EXPORT Result Run (const QString &executable, const QStringList &args, int finishedTimeoutMs=-1)
 Runs executable with args in a clean environment and blocks until it finishes. More...
 

Detailed Description

Helpers for running an executable from a MITK-managed Python virtual environment as a subprocess.

Centralises the one invariant every such call must honour: the child runs with PYTHONHOME / PYTHONPATH stripped, so it resolves its environment from the venv's own layout (pyvenv.cfg and site-packages) instead of MITK's embedded interpreter. Keeping that in a single place stops the historically duplicated copies of the pattern from drifting.

Function Documentation

◆ CleanEnvironment()

MITKPYTHONSEGMENTATIONUI_EXPORT QProcessEnvironment QmitkVenvProcess::CleanEnvironment ( )

The current process environment with PYTHONHOME and PYTHONPATH removed.

◆ Run()

MITKPYTHONSEGMENTATIONUI_EXPORT Result QmitkVenvProcess::Run ( const QString &  executable,
const QStringList &  args,
int  finishedTimeoutMs = -1 
)

Runs executable with args in a clean environment and blocks until it finishes.

Blocks the calling thread, so run it from a worker thread (e.g. via QmitkRunAsyncBlocking) rather than directly on the GUI thread.

Parameters
executableThe executable to run.
argsCommand-line arguments passed to executable.
finishedTimeoutMsMilliseconds to wait for completion; a negative value waits indefinitely. On start failure or timeout the process is killed and Result::success stays false.

◆ ToQString()

MITKPYTHONSEGMENTATIONUI_EXPORT QString QmitkVenvProcess::ToQString ( const fs::path &  path)

Lossless conversion of a filesystem path to a QString.

fs::path::string() re-encodes to the native narrow code page on Windows, which corrupts non-ASCII paths (e.g. a venv under a user profile with accented characters) before they reach QProcess. Convert from the wide / native representation instead.