From 744d689eee15c41b61bbb7e7d8cf68212874a15b Mon Sep 17 00:00:00 2001 From: peri4 Date: Mon, 14 Oct 2024 18:36:04 +0300 Subject: [PATCH] add qCallQueued --- libs/piqt/piqt_macros.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/libs/piqt/piqt_macros.h b/libs/piqt/piqt_macros.h index d9f59a7..86d623f 100644 --- a/libs/piqt/piqt_macros.h +++ b/libs/piqt/piqt_macros.h @@ -44,6 +44,20 @@ PIQt::qpiConnect(src, &decltype(PIQt::removePtr(src))::sig, tgt, &(tgt)->__stat_eh_##handler##__); +/// much more compact and easy to use alternative to QMetaObject::invokeMethod(... , Qt::QueuedConnection) +/// examples: +/// qCallQueued(this, &MyClass::myFunc); +/// qCallQueued(this, &MyClass::myFuncWithInt, 0xFF); +/// qCallQueued(this, &MyClass::myFuncWithIntAndString, 0xAB, "string"); +template +void qCallQueued(O * o, F f, Args... args) { + QMetaObject::invokeMethod( + o, + [o, f, args...]() { (o->*f)(args...); }, + Qt::QueuedConnection); +} + + namespace PIQt { template