From 8ed10368394bcfa84a8b46ea38d75faa81af93ef Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Tue, 8 May 2018 10:32:22 +0200 Subject: [PATCH] memory leak fixed - buttons were not deleted in case of dialogs, that have never been shown --- src/dialogs/QskDialogButtonBox.cpp | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/dialogs/QskDialogButtonBox.cpp b/src/dialogs/QskDialogButtonBox.cpp index 8ca78f6a..620276d0 100644 --- a/src/dialogs/QskDialogButtonBox.cpp +++ b/src/dialogs/QskDialogButtonBox.cpp @@ -90,17 +90,6 @@ void QskDialogButtonBox::setOrientation( Qt::Orientation orientation ) if ( m_data->layoutBox && m_data->layoutBox->orientation() == orientation ) return; - for ( int i = 0; i < QskDialog::NButtonRoles; i++ ) - { - for ( QskPushButton* button : qskAsConst( m_data->buttonLists[i] ) ) - { - // avoid that buttons get deleted - // together with the layout - - button->setParent( nullptr ); - } - } - delete m_data->layoutBox; m_data->layoutBox = new QskLinearBox( orientation, this ); @@ -263,10 +252,17 @@ void QskDialogButtonBox::addButton( QskPushButton* button, QskDialog::ButtonRole if ( role < 0 || role >= QskDialog::NButtonRoles ) return; - connect( button, &QskPushButton::clicked, this, &QskDialogButtonBox::onButtonClicked ); + if ( button ) + { + if ( button->parent() == nullptr ) + button->setParent( this ); - m_data->buttonLists[role] += button; - invalidateLayout(); + connect( button, &QskPushButton::clicked, this, + &QskDialogButtonBox::onButtonClicked ); + + m_data->buttonLists[role] += button; + invalidateLayout(); + } } void QskDialogButtonBox::addButton( QskDialog::StandardButton standardButton )