Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Merge pull request #5829 from ligfx/qtmsgalerthandler
Qt: register MsgAlertHandler
- Loading branch information
Showing
6 changed files
with
114 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| // Copyright 2017 Dolphin Emulator Project | ||
| // Licensed under GPLv2+ | ||
| // Refer to the license.txt file included. | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <type_traits> | ||
| #include <utility> | ||
|
|
||
| #include "Common/Event.h" | ||
| #include "DolphinQt2/QtUtils/QueueOnObject.h" | ||
|
|
||
| class QObject; | ||
|
|
||
| // QWidget and subclasses are not thread-safe! This helper takes arbitrary code from any thread, | ||
| // safely runs it on the appropriate GUI thread, waits for it to finish, and returns the result. | ||
|
|
||
| template <typename F> | ||
| auto RunOnObject(QObject* object, F&& functor) | ||
| { | ||
| // If we queue up a functor on the current thread, it won't run until we return to the event loop, | ||
| // which means waiting for it to finish will never complete. Instead, run it immediately. | ||
| if (object->thread() == QThread::currentThread()) | ||
| return functor(); | ||
|
|
||
| Common::Event event; | ||
| std::result_of_t<F()> result; | ||
| QueueOnObject(object, [&event, &result, functor = std::forward<F>(functor) ] { | ||
| result = functor(); | ||
| event.Set(); | ||
| }); | ||
| event.Wait(); | ||
| return result; | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters