QtUtils/RunOnObject: Make safe under object destruction

Co-Authored-By: cancel <cancel@cancel.fm>
This commit is contained in:
riking 2018-05-21 15:27:12 -07:00
parent f31f1a08fb
commit 268b424843
5 changed files with 61 additions and 13 deletions

View file

@ -580,12 +580,15 @@ void NetPlayDialog::OnTraversalError(TraversalClient::FailureReason error)
bool NetPlayDialog::IsRecording()
{
return RunOnObject(m_record_input_box, &QCheckBox::isChecked);
std::optional<bool> is_recording = RunOnObject(m_record_input_box, &QCheckBox::isChecked);
if (is_recording)
return *is_recording;
return false;
}
std::string NetPlayDialog::FindGame(const std::string& game)
{
return RunOnObject(this, [this, game] {
std::optional<std::string> path = RunOnObject(this, [this, game] {
for (int i = 0; i < m_game_list_model->rowCount(QModelIndex()); i++)
{
if (m_game_list_model->GetUniqueIdentifier(i).toStdString() == game)
@ -593,6 +596,9 @@ std::string NetPlayDialog::FindGame(const std::string& game)
}
return std::string("");
});
if (path)
return *path;
return std::string("");
}
void NetPlayDialog::ShowMD5Dialog(const std::string& file_identifier)