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();
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("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]);
QMenu* menu = new QMenu(this);
menu->setAttribute(Qt::WA_DeleteOnClose, true);
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());
QMenu* const menu = new QMenu;
menu->setAttribute(Qt::WA_DeleteOnClose, true);
menu->addAction(tr("&Delete"), [this, index_list]() { OnTableDelete(std::move(index_list)); });
switch (index.column())
{

View File

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

View File

@ -558,6 +558,7 @@ void CodeViewWidget::ReplaceAddress(u32 address, ReplaceWith replace)
void CodeViewWidget::OnContextMenu()
{
QMenu* menu = new QMenu(this);
menu->setAttribute(Qt::WA_DeleteOnClose, true);
const bool running = Core::GetState(m_system) != Core::State::Uninitialized;
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);
auto* menu = new QMenu(this);
menu->setAttribute(Qt::WA_DeleteOnClose, true);
menu->addAction(tr("Copy Address"), this, [this, addr] { OnCopyAddress(addr); });

View File

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

View File

@ -119,6 +119,8 @@ void ThreadWidget::ShowContextMenu(QTableWidget* table)
return;
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'));
menu->addAction(tr("Add &breakpoint"), this, [this, addr] { emit RequestBreakpoint(addr); });
menu->addAction(tr("Add memory breakpoint"), this,

View File

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

View File

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

View File

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