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

@ -34,7 +34,7 @@
static bool QtMsgAlertHandler(const char* caption, const char* text, bool yes_no, MsgType style)
{
return RunOnObject(QApplication::instance(), [&] {
std::optional<bool> r = RunOnObject(QApplication::instance(), [&] {
QMessageBox message_box(QApplication::activeWindow());
message_box.setWindowTitle(QString::fromUtf8(caption));
message_box.setText(QString::fromUtf8(text));
@ -68,6 +68,9 @@ static bool QtMsgAlertHandler(const char* caption, const char* text, bool yes_no
return false;
});
if (r.has_value())
return *r;
return false;
}
// N.B. On Windows, this should be called from WinMain. Link against qtmain and specify