[locale] Simplify allocation, guard against crashes if the dialog is deleted.

This commit is contained in:
Adriaan de Groot 2020-07-21 14:57:09 +02:00
parent 66eacce654
commit abc98cfa79

View File

@ -38,6 +38,7 @@
#include <QComboBox> #include <QComboBox>
#include <QFile> #include <QFile>
#include <QLabel> #include <QLabel>
#include <QPointer>
#include <QProcess> #include <QProcess>
#include <QPushButton> #include <QPushButton>
@ -285,31 +286,31 @@ LocalePage::locationChanged( const CalamaresUtils::Locale::TZZone* location )
void void
LocalePage::changeLocale() LocalePage::changeLocale()
{ {
LCLocaleDialog* dlg QPointer< LCLocaleDialog > dlg(
= new LCLocaleDialog( m_config->localeConfiguration().language(), m_config->supportedLocales(), this ); new LCLocaleDialog( m_config->localeConfiguration().language(), m_config->supportedLocales(), this ) );
dlg->exec(); dlg->exec();
if ( dlg->result() == QDialog::Accepted && !dlg->selectedLCLocale().isEmpty() ) if ( dlg && dlg->result() == QDialog::Accepted && !dlg->selectedLCLocale().isEmpty() )
{ {
m_config->setLanguageExplicitly( dlg->selectedLCLocale() ); m_config->setLanguageExplicitly( dlg->selectedLCLocale() );
updateGlobalLocale(); updateGlobalLocale();
updateLocaleLabels(); updateLocaleLabels();
} }
dlg->deleteLater(); delete dlg;
} }
void void
LocalePage::changeFormats() LocalePage::changeFormats()
{ {
LCLocaleDialog* dlg QPointer< LCLocaleDialog > dlg(
= new LCLocaleDialog( m_config->localeConfiguration().lc_numeric, m_config->supportedLocales(), this ); new LCLocaleDialog( m_config->localeConfiguration().lc_numeric, m_config->supportedLocales(), this ) );
dlg->exec(); dlg->exec();
if ( dlg->result() == QDialog::Accepted && !dlg->selectedLCLocale().isEmpty() ) if ( dlg && dlg->result() == QDialog::Accepted && !dlg->selectedLCLocale().isEmpty() )
{ {
m_config->setLCLocaleExplicitly( dlg->selectedLCLocale() ); m_config->setLCLocaleExplicitly( dlg->selectedLCLocale() );
updateLocaleLabels(); updateLocaleLabels();
} }
dlg->deleteLater(); delete dlg;
} }