diff options
author | Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> | 2020-08-14 20:46:32 +0300 |
---|---|---|
committer | Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> | 2020-11-25 16:12:23 +0200 |
commit | 5659e73493fcdfb5d0cb9d686c24c4fbe1c217ed (patch) | |
tree | 92e38fc5475fa7a9553d9675c7ac821e231ca43e /src/qt/guiutil.h | |
parent | afdfd3c8c1ce96adae11809e3989de381137fee9 (diff) |
qt: Add ObjectInvoke template function
This is a replacement of the QMetaObject::invokeMethod functor overload
which is available in Qt 5.10+.
Co-authored-by: Russell Yanofsky <russ@yanofsky.org>
Diffstat (limited to 'src/qt/guiutil.h')
-rw-r--r-- | src/qt/guiutil.h | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/qt/guiutil.h b/src/qt/guiutil.h index c976b4b4bb..d7bd124884 100644 --- a/src/qt/guiutil.h +++ b/src/qt/guiutil.h @@ -340,6 +340,18 @@ namespace GUIUtil #endif } + /** + * Queue a function to run in an object's event loop. This can be + * replaced by a call to the QMetaObject::invokeMethod functor overload after Qt 5.10, but + * for now use a QObject::connect for compatibility with older Qt versions, based on + * https://stackoverflow.com/questions/21646467/how-to-execute-a-functor-or-a-lambda-in-a-given-thread-in-qt-gcd-style + */ + template <typename Fn> + void ObjectInvoke(QObject* object, Fn&& function, Qt::ConnectionType connection = Qt::QueuedConnection) + { + QObject source; + QObject::connect(&source, &QObject::destroyed, object, std::forward<Fn>(function), connection); + } } // namespace GUIUtil |