DolphinQt: Properly Delete (Some) Widgets

This is not every memory leak, just the ones that were obvious.
This commit is contained in:
mitaclaw 2024-04-30 10:58:16 -07:00
parent e69486d2cb
commit 0397339ab1
12 changed files with 25 additions and 9 deletions

View file

@ -495,6 +495,7 @@ void CheatSearchWidget::OnAddressTableContextMenu()
const u32 address = item->data(ADDRESS_TABLE_ADDRESS_ROLE).toUInt(); const u32 address = item->data(ADDRESS_TABLE_ADDRESS_ROLE).toUInt();
QMenu* menu = new QMenu(this); QMenu* menu = new QMenu(this);
menu->setAttribute(Qt::WA_DeleteOnClose, true);
menu->addAction(tr("Show in memory"), [this, address] { emit ShowMemory(address); }); menu->addAction(tr("Show in memory"), [this, address] { emit ShowMemory(address); });
menu->addAction(tr("Add to watch"), this, [this, address] { menu->addAction(tr("Add to watch"), this, [this, address] {

View file

@ -226,6 +226,7 @@ void FilesystemWidget::ShowContextMenu(const QPoint&)
auto* item = m_tree_model->itemFromIndex(selection->selectedIndexes()[0]); auto* item = m_tree_model->itemFromIndex(selection->selectedIndexes()[0]);
QMenu* menu = new QMenu(this); QMenu* menu = new QMenu(this);
menu->setAttribute(Qt::WA_DeleteOnClose, true);
EntryType type = item->data(ENTRY_TYPE).value<EntryType>(); EntryType type = item->data(ENTRY_TYPE).value<EntryType>();

View file

@ -806,6 +806,8 @@ void BranchWatchDialog::OnTableContextMenu(const QPoint& pos)
QModelIndexList index_list = m_table_view->selectionModel()->selectedRows(index.column()); QModelIndexList index_list = m_table_view->selectionModel()->selectedRows(index.column());
QMenu* const menu = new QMenu; QMenu* const menu = new QMenu;
menu->setAttribute(Qt::WA_DeleteOnClose, true);
menu->addAction(tr("&Delete"), [this, index_list]() { OnTableDelete(std::move(index_list)); }); menu->addAction(tr("&Delete"), [this, index_list]() { OnTableDelete(std::move(index_list)); });
switch (index.column()) switch (index.column())
{ {

View file

@ -309,6 +309,7 @@ void BreakpointWidget::OnClear()
void BreakpointWidget::OnNewBreakpoint() void BreakpointWidget::OnNewBreakpoint()
{ {
BreakpointDialog* dialog = new BreakpointDialog(this); BreakpointDialog* dialog = new BreakpointDialog(this);
dialog->setAttribute(Qt::WA_DeleteOnClose, true);
SetQWidgetWindowDecorations(dialog); SetQWidgetWindowDecorations(dialog);
dialog->exec(); dialog->exec();
} }
@ -319,6 +320,7 @@ void BreakpointWidget::OnEditBreakpoint(u32 address, bool is_instruction_bp)
{ {
auto* dialog = auto* dialog =
new BreakpointDialog(this, m_system.GetPowerPC().GetBreakPoints().GetBreakpoint(address)); new BreakpointDialog(this, m_system.GetPowerPC().GetBreakPoints().GetBreakpoint(address));
dialog->setAttribute(Qt::WA_DeleteOnClose, true);
SetQWidgetWindowDecorations(dialog); SetQWidgetWindowDecorations(dialog);
dialog->exec(); dialog->exec();
} }
@ -326,6 +328,7 @@ void BreakpointWidget::OnEditBreakpoint(u32 address, bool is_instruction_bp)
{ {
auto* dialog = auto* dialog =
new BreakpointDialog(this, m_system.GetPowerPC().GetMemChecks().GetMemCheck(address)); new BreakpointDialog(this, m_system.GetPowerPC().GetMemChecks().GetMemCheck(address));
dialog->setAttribute(Qt::WA_DeleteOnClose, true);
SetQWidgetWindowDecorations(dialog); SetQWidgetWindowDecorations(dialog);
dialog->exec(); dialog->exec();
} }
@ -387,6 +390,7 @@ void BreakpointWidget::OnContextMenu()
const auto is_memory_breakpoint = selected_item->data(IS_MEMCHECK_ROLE).toBool(); const auto is_memory_breakpoint = selected_item->data(IS_MEMCHECK_ROLE).toBool();
auto* menu = new QMenu(this); auto* menu = new QMenu(this);
menu->setAttribute(Qt::WA_DeleteOnClose, true);
if (!is_memory_breakpoint) if (!is_memory_breakpoint)
{ {

View file

@ -558,6 +558,7 @@ void CodeViewWidget::ReplaceAddress(u32 address, ReplaceWith replace)
void CodeViewWidget::OnContextMenu() void CodeViewWidget::OnContextMenu()
{ {
QMenu* menu = new QMenu(this); QMenu* menu = new QMenu(this);
menu->setAttribute(Qt::WA_DeleteOnClose, true);
const bool running = Core::GetState(m_system) != Core::State::Uninitialized; const bool running = Core::GetState(m_system) != Core::State::Uninitialized;
const bool paused = Core::GetState(m_system) == Core::State::Paused; const bool paused = Core::GetState(m_system) == Core::State::Paused;

View file

@ -873,6 +873,7 @@ void MemoryViewWidget::OnContextMenu(const QPoint& pos)
->IsValidAddress(Core::CPUThreadGuard{m_system}, addr); ->IsValidAddress(Core::CPUThreadGuard{m_system}, addr);
auto* menu = new QMenu(this); auto* menu = new QMenu(this);
menu->setAttribute(Qt::WA_DeleteOnClose, true);
menu->addAction(tr("Copy Address"), this, [this, addr] { OnCopyAddress(addr); }); menu->addAction(tr("Copy Address"), this, [this, addr] { OnCopyAddress(addr); });

View file

@ -118,6 +118,7 @@ void RegisterWidget::OnItemChanged(QTableWidgetItem* item)
void RegisterWidget::ShowContextMenu() void RegisterWidget::ShowContextMenu()
{ {
QMenu* menu = new QMenu(this); QMenu* menu = new QMenu(this);
menu->setAttribute(Qt::WA_DeleteOnClose, true);
auto* raw_item = m_table->currentItem(); auto* raw_item = m_table->currentItem();

View file

@ -119,6 +119,8 @@ void ThreadWidget::ShowContextMenu(QTableWidget* table)
return; return;
QMenu* menu = new QMenu(this); QMenu* menu = new QMenu(this);
menu->setAttribute(Qt::WA_DeleteOnClose, true);
const QString watch_name = QStringLiteral("thread_context_%1").arg(addr, 8, 16, QLatin1Char('0')); const QString watch_name = QStringLiteral("thread_context_%1").arg(addr, 8, 16, QLatin1Char('0'));
menu->addAction(tr("Add &breakpoint"), this, [this, addr] { emit RequestBreakpoint(addr); }); menu->addAction(tr("Add &breakpoint"), this, [this, addr] { emit RequestBreakpoint(addr); });
menu->addAction(tr("Add memory breakpoint"), this, menu->addAction(tr("Add memory breakpoint"), this,

View file

@ -327,6 +327,7 @@ void WatchWidget::OnSave()
void WatchWidget::ShowContextMenu() void WatchWidget::ShowContextMenu()
{ {
QMenu* menu = new QMenu(this); QMenu* menu = new QMenu(this);
menu->setAttribute(Qt::WA_DeleteOnClose, true);
if (!m_table->selectedItems().empty()) if (!m_table->selectedItems().empty())
{ {

View file

@ -372,6 +372,7 @@ void GameList::ShowContextMenu(const QPoint&)
return; return;
QMenu* menu = new QMenu(this); QMenu* menu = new QMenu(this);
menu->setAttribute(Qt::WA_DeleteOnClose, true);
if (HasMultipleSelected()) if (HasMultipleSelected())
{ {

View file

@ -295,19 +295,19 @@ void NetPlayBrowser::accept()
if (m_sessions[index].has_password) if (m_sessions[index].has_password)
{ {
auto* dialog = new QInputDialog(this); QInputDialog dialog(this);
dialog->setWindowFlags(dialog->windowFlags() & ~Qt::WindowContextHelpButtonHint); dialog.setWindowFlags(dialog.windowFlags() & ~Qt::WindowContextHelpButtonHint);
dialog->setWindowTitle(tr("Enter password")); dialog.setWindowTitle(tr("Enter password"));
dialog->setLabelText(tr("This session requires a password:")); dialog.setLabelText(tr("This session requires a password:"));
dialog->setWindowModality(Qt::WindowModal); dialog.setWindowModality(Qt::WindowModal);
dialog->setTextEchoMode(QLineEdit::Password); dialog.setTextEchoMode(QLineEdit::Password);
SetQWidgetWindowDecorations(dialog); SetQWidgetWindowDecorations(&dialog);
if (dialog->exec() != QDialog::Accepted) if (dialog.exec() != QDialog::Accepted)
return; return;
const std::string password = dialog->textValue().toStdString(); const std::string password = dialog.textValue().toStdString();
auto decrypted_id = session.DecryptID(password); auto decrypted_id = session.DecryptID(password);

View file

@ -57,6 +57,7 @@ void Updater::OnUpdateAvailable(const NewVersionInformation& info)
std::optional<int> choice = RunOnObject(m_parent, [&] { std::optional<int> choice = RunOnObject(m_parent, [&] {
QDialog* dialog = new QDialog(m_parent); QDialog* dialog = new QDialog(m_parent);
dialog->setAttribute(Qt::WA_DeleteOnClose, true);
dialog->setWindowTitle(tr("Update available")); dialog->setWindowTitle(tr("Update available"));
dialog->setWindowFlags(dialog->windowFlags() & ~Qt::WindowContextHelpButtonHint); dialog->setWindowFlags(dialog->windowFlags() & ~Qt::WindowContextHelpButtonHint);