diff --git a/src/blackmisc/slot.h b/src/blackmisc/slot.h index 67e8a8d60..d83b4afed 100644 --- a/src/blackmisc/slot.h +++ b/src/blackmisc/slot.h @@ -11,14 +11,17 @@ #ifndef BLACKMISC_SLOT_H #define BLACKMISC_SLOT_H +#include "blackmisc/invoke.h" + #include #include #include +#include + #include #include #include #include -#include "blackmisc/invoke.h" namespace BlackMisc { @@ -100,6 +103,19 @@ namespace BlackMisc return m_function(args...); } + //! Call function "de-coupled" in original thread + bool singleShot(Args... args) const + { + // does NOT return the values of m_function! + if (!m_object || !m_function) { return false; } + QTimer::singleShot(0, m_object.data(), [ = ] + { + if (!m_object || !m_function) { return; } + m_function(args...); + }); + return true; + } + //! Returns the object which the slot belongs to. //! Use this as the third argument to QObject::connect to ensure the slot is called in the correct thread. QObject *object() const