mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-06-12 18:01:57 +02:00
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>
This commit is contained in:
parent
afdfd3c8c1
commit
5659e73493
@ -340,6 +340,18 @@ namespace GUIUtil
|
|||||||
#endif
|
#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
|
} // namespace GUIUtil
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user