Skip to content

Commit

Permalink
Use deleteLater to safely del QObject instances
Browse files Browse the repository at this point in the history
  • Loading branch information
Inokinoki committed May 2, 2022
1 parent c02502f commit 73ed29b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 21 deletions.
2 changes: 1 addition & 1 deletion mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ MainWindow::MainWindow(QWidget *parent)

MainWindow::~MainWindow()
{
if (m_entryView != nullptr) delete m_entryView;
if (m_entryView != nullptr) m_entryView->deleteLater();
}

7 changes: 3 additions & 4 deletions qefientrydetailview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ QEFIEntryDetailBriefView::QEFIEntryDetailBriefView(

QEFIEntryDetailBriefView::~QEFIEntryDetailBriefView()
{
if (m_briefLayout != nullptr) delete m_briefLayout;
if (m_briefLayout != nullptr) m_briefLayout->deleteLater();
m_briefLayout = nullptr;
}

Expand Down Expand Up @@ -71,10 +71,9 @@ QEFIEntryDetailView::QEFIEntryDetailView(QEFIEntry &entry, QWidget *parent)

QEFIEntryDetailView::~QEFIEntryDetailView()
{
if (m_topLevelLayout != nullptr) delete m_topLevelLayout;
if (m_topLevelLayout != nullptr) m_topLevelLayout->deleteLater();
m_topLevelLayout = nullptr;

// Has ownership been passed to layout?
if (m_tab != nullptr) delete m_tab;
if (m_tab != nullptr) m_tab->deleteLater();
m_tab = nullptr;
}
3 changes: 1 addition & 2 deletions qefientrydpdetailview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ QEFIEntryDPDetailView::QEFIEntryDPDetailView(QEFIDevicePath *dp, QWidget *parent

QEFIEntryDPDetailView::~QEFIEntryDPDetailView()
{
// TODO: Use smart ptr
if (m_topLevelLayout != nullptr) {
delete m_topLevelLayout;
m_topLevelLayout->deleteLater();
m_topLevelLayout = nullptr;
}
}
26 changes: 12 additions & 14 deletions qefientryview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,26 +89,24 @@ QEFIEntryView::QEFIEntryView(QWidget *parent)

QEFIEntryView::~QEFIEntryView()
{
// TODO: Use smart ptr
if (m_topLevelLayout != nullptr) {
delete m_topLevelLayout;
m_topLevelLayout->deleteLater();
m_topLevelLayout = nullptr;
}

if (m_entries != nullptr) delete m_entries;
if (m_entries != nullptr) m_entries->deleteLater();
m_entries = nullptr;

// Seems that we have no ownership on it
// if (m_buttonLayout != nullptr) delete m_buttonLayout;
// m_buttonLayout = nullptr;

if (m_moveUpEntryButton != nullptr) delete m_moveUpEntryButton;
if (m_moveDownEntryButton != nullptr) delete m_moveDownEntryButton;
if (m_setCurrentButton != nullptr) delete m_setCurrentButton;
if (m_saveButton != nullptr) delete m_saveButton;
if (m_resetButton != nullptr) delete m_resetButton;
if (m_rebootTargetButton != nullptr) delete m_rebootTargetButton;
if (m_bootTimeoutLabel != nullptr) delete m_bootTimeoutLabel;
if (m_buttonLayout != nullptr) m_buttonLayout->deleteLater();

if (m_moveUpEntryButton != nullptr) m_moveUpEntryButton->deleteLater();
if (m_moveDownEntryButton != nullptr) m_moveDownEntryButton->deleteLater();
if (m_setCurrentButton != nullptr) m_setCurrentButton->deleteLater();
if (m_saveButton != nullptr) m_saveButton->deleteLater();
if (m_resetButton != nullptr) m_resetButton->deleteLater();
if (m_rebootTargetButton != nullptr) m_rebootTargetButton->deleteLater();
if (m_bootTimeoutLabel != nullptr) m_bootTimeoutLabel->deleteLater();
}

void QEFIEntryView::entryChanged(int currentRow)
Expand Down Expand Up @@ -286,7 +284,7 @@ class DetailDialog : public QDialog

~DetailDialog()
{
if (m_topLevelLayout) delete m_topLevelLayout;
if (m_topLevelLayout) m_topLevelLayout->deleteLater();
}
};

Expand Down

0 comments on commit 73ed29b

Please sign in to comment.