use QWeakPointer (and explicit deletion, if needed) instead of QSharedPointer

CCBUG: 277925
This commit is contained in:
Hugo Pereira Da Costa 2011-07-17 15:47:54 +02:00
parent 5c95478e56
commit 7ca4d15919

View file

@ -27,7 +27,7 @@
#include "oxygenexceptionlistwidget.moc" #include "oxygenexceptionlistwidget.moc"
#include "oxygenexceptiondialog.h" #include "oxygenexceptiondialog.h"
#include <QtCore/QSharedPointer> #include <QtCore/QWeakPointer>
#include <KLocale> #include <KLocale>
#include <KMessageBox> #include <KMessageBox>
@ -113,13 +113,14 @@ namespace Oxygen
{ {
// map dialog // map dialog
QSharedPointer<ExceptionDialog> dialog( new ExceptionDialog( this ) ); QWeakPointer<ExceptionDialog> dialog( new ExceptionDialog( this ) );
dialog->setException( _defaultConfiguration ); dialog.data()->setException( _defaultConfiguration );
if( dialog->exec() == QDialog::Rejected ) return; if( dialog.data()->exec() == QDialog::Rejected || !dialog ) return;
// retrieve exception and check // retrieve exception and check
Exception exception( dialog->exception() ); Exception exception( dialog.data()->exception() );
if( !checkException( exception ) ) return; if( !checkException( exception ) ) return;
delete dialog.data();
// create new item // create new item
model().add( exception ); model().add( exception );
@ -149,12 +150,13 @@ namespace Oxygen
Exception& exception( model().get( current ) ); Exception& exception( model().get( current ) );
// create dialog // create dialog
QSharedPointer<ExceptionDialog> dialog( new ExceptionDialog( this ) ); QWeakPointer<ExceptionDialog> dialog( new ExceptionDialog( this ) );
dialog->setException( exception ); dialog.data()->setException( exception );
// map dialog // map dialog
if( dialog->exec() == QDialog::Rejected ) return; if( dialog.data()->exec() == QDialog::Rejected || !dialog ) return;
Exception newException = dialog->exception(); Exception newException = dialog.data()->exception();
delete dialog.data();
// check if exception was changed // check if exception was changed
if( exception == newException ) return; if( exception == newException ) return;
@ -310,10 +312,11 @@ namespace Oxygen
{ {
KMessageBox::error( this, i18n("Regular Expression syntax is incorrect") ); KMessageBox::error( this, i18n("Regular Expression syntax is incorrect") );
QSharedPointer<ExceptionDialog> dialog( new ExceptionDialog( this ) ); QWeakPointer<ExceptionDialog> dialog( new ExceptionDialog( this ) );
dialog->setException( exception ); dialog.data()->setException( exception );
if( dialog->exec() == QDialog::Rejected ) return false; if( dialog.data()->exec() == QDialog::Rejected || !dialog ) return false;
exception = dialog->exception(); exception = dialog.data()->exception();
delete dialog.data();
} }