Skip to content
Snippets Groups Projects
Commit ed12b111 authored by Otmane Lahlou's avatar Otmane Lahlou
Browse files

ENH : avoid segfaults by removing the observators when the QtProgressBar is...

ENH : avoid segfaults by removing the observators when the QtProgressBar is deleted, and make the caller smartpointer
parent 64c1aeb8
No related branches found
No related tags found
No related merge requests found
...@@ -9,8 +9,8 @@ ...@@ -9,8 +9,8 @@
Copyright (c) 2002 Insight Consortium. All rights reserved. Copyright (c) 2002 Insight Consortium. All rights reserved.
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information. PURPOSE. See the above copyright notices for more information.
=========================================================================*/ =========================================================================*/
...@@ -29,11 +29,16 @@ QtProgressBar::QtProgressBar( QWidget *parent):QProgressBar(parent) ...@@ -29,11 +29,16 @@ QtProgressBar::QtProgressBar( QWidget *parent):QProgressBar(parent)
m_RedrawCommand->SetCallbackFunction( this, &QtProgressBar::ProcessEvent ); m_RedrawCommand->SetCallbackFunction( this, &QtProgressBar::ProcessEvent );
m_RedrawCommand->SetCallbackFunction( this, &QtProgressBar::ConstProcessEvent ); m_RedrawCommand->SetCallbackFunction( this, &QtProgressBar::ConstProcessEvent );
m_Caller = itk::Object::New();
this->setMaximum( 100 ); this->setMaximum( 100 );
this->reset(); this->reset();
} }
QtProgressBar::~QtProgressBar()
{
m_Caller->RemoveAllObservers();
}
/** Get Command */ /** Get Command */
QtProgressBar::RedrawCommandType * QtProgressBar::RedrawCommandType *
...@@ -45,31 +50,31 @@ QtProgressBar::GetRedrawCommand( void ) const ...@@ -45,31 +50,31 @@ QtProgressBar::GetRedrawCommand( void ) const
/** Manage a Progress event */ /** Manage a Progress event */
void void
QtProgressBar::ProcessEvent( itk::Object * caller, QtProgressBar::ProcessEvent( itk::Object * caller,
const itk::EventObject & event ) const itk::EventObject & event )
{ {
if( typeid( itk::ProgressEvent ) == typeid( event ) ) if( typeid( itk::ProgressEvent ) == typeid( event ) )
{ {
::itk::ProcessObject::Pointer process = ::itk::ProcessObject::Pointer process =
dynamic_cast< itk::ProcessObject *>( caller ); dynamic_cast< itk::ProcessObject *>( caller );
const int value = static_cast<int>( const int value = static_cast<int>(
process->GetProgress() * this->maximum() ); process->GetProgress() * this->maximum() );
emit SetValueChanged( value ); emit SetValueChanged( value );
} }
} }
void void
QtProgressBar::ConstProcessEvent( const itk::Object * caller, QtProgressBar::ConstProcessEvent( const itk::Object * caller,
const itk::EventObject & event ) const itk::EventObject & event )
{ {
if( typeid( itk::ProgressEvent ) == typeid( event ) ) if( typeid( itk::ProgressEvent ) == typeid( event ) )
{ {
itk::ProcessObject::ConstPointer process = itk::ProcessObject::ConstPointer process =
dynamic_cast< const itk::ProcessObject *>( caller ); dynamic_cast< const itk::ProcessObject *>( caller );
const int value = static_cast<int>( const int value = static_cast<int>(
process->GetProgress() * this->maximum() ); process->GetProgress() * this->maximum() );
emit SetValueChanged( value ); emit SetValueChanged( value );
} }
...@@ -79,7 +84,8 @@ QtProgressBar::ConstProcessEvent( const itk::Object * caller, ...@@ -79,7 +84,8 @@ QtProgressBar::ConstProcessEvent( const itk::Object * caller,
void void
QtProgressBar::Observe( itk::Object *caller ) QtProgressBar::Observe( itk::Object *caller )
{ {
caller->AddObserver( itk::ProgressEvent(), m_RedrawCommand.GetPointer() ); m_Caller = caller;
m_Caller->AddObserver( itk::ProgressEvent(), m_RedrawCommand.GetPointer() );
} }
} // end namespace fltk } // end namespace fltk
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
Copyright (c) 2002 Insight Consortium. All rights reserved. Copyright (c) 2002 Insight Consortium. All rights reserved.
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information. PURPOSE. See the above copyright notices for more information.
...@@ -31,6 +31,9 @@ public: ...@@ -31,6 +31,9 @@ public:
/** Constructor */ /** Constructor */
QtProgressBar( QWidget *parent ); QtProgressBar( QWidget *parent );
/** Destructor */
~QtProgressBar();
/** Get Command */ /** Get Command */
RedrawCommandType * GetRedrawCommand( void ) const; RedrawCommandType * GetRedrawCommand( void ) const;
...@@ -47,7 +50,7 @@ signals: ...@@ -47,7 +50,7 @@ signals:
void SetValueChanged(int); void SetValueChanged(int);
private: private:
itk::Object::Pointer m_Caller;
RedrawCommandType::Pointer m_RedrawCommand; RedrawCommandType::Pointer m_RedrawCommand;
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment