Medical Imaging Interaction Toolkit  2018.4.99-12ad79a3 Medical Imaging Interaction Toolkit

Allows threads to call some method from within the GUI thread. More...

#include <mitkCallbackFromGUIThread.h>

## Public Member Functions

void CallThisFromGUIThread (itk::Command *, itk::EventObject *e=nullptr)
Change the current application cursor. More...

## Static Public Member Functions

This class is a singleton. More...

To be called by a toolkit specific CallbackFromGUIThreadImplementation. More...

## Protected Member Functions

Purposely hidden - singleton. More...

## Detailed Description

This class is useful for use with GUI toolkits that are not thread-safe, e.g. Qt. Any thread that needs to work with the GUI at some time during its execution (e.g. at the end, to display some results) can use this class to ask for a call to a member function from the GUI thread.

Usage example

We assume that you have a class ThreadedClass, that basically lives in a thread that is different from the GUI thread. Now this class has to change some element of the GUI to indicate its status. This could be dangerous (with Qt it is for sure).

{
public:
... // All you need
// This function runs in its own thread !
// This should be called from the GUI thread
void ChangeGUIElementsToIndicateProgress(const itk::EventObject&);
...
};
#include <itkCommand.h>
// This method runs in a thread of its own! So it can't manipulate GUI elements directly without causing trouble
{
...
// Create a command object (passing parameters comes later)
...
}
// Do dangerous GUI changing stuff here
{
Application::GetButtonGrid()->AddButton("Stop"); // this is pseudo code
}

This obviously won't allow you to pass parameters to ChangeGUIElementsToIndicateProgress. If you need to do that, you have to create a kind of itk::EventObject that can be asked for a parameter (this solution is not nice, if you see a better solution, please mail to mitk-.nosp@m.user.nosp@m.s@lis.nosp@m.ts.s.nosp@m.ource.nosp@m.forg.nosp@m.e.net).

The itk::EventObject has to be created with "new" (which can also be done by calling MakeObject on an existing EventObject).

const mitk::OneParameterEvent* event = new mitk::OneParameterEvent(1); // this class is not yet defined but will
be
// DO NOT delete event now. This will be done by CallThisFromGUIThread after the command will executed.

Definition at line 153 of file mitkCallbackFromGUIThread.h.

## Constructor & Destructor Documentation

protected

Purposely hidden - singleton.

Definition at line 21 of file mitkCallbackFromGUIThread.cpp.

Referenced by GetInstance().

## Member Function Documentation

 void mitk::CallbackFromGUIThread::CallThisFromGUIThread ( itk::Command * cmd, itk::EventObject * e = nullptr )

Change the current application cursor.

Definition at line 37 of file mitkCallbackFromGUIThread.cpp.

## ◆ GetInstance()

static

This class is a singleton.

Definition at line 22 of file mitkCallbackFromGUIThread.cpp.