Reputation: 7749
In Qt, I often use something like QMetaObject::invokeMethod(this, "myMethod", Q_ARG(bool, foo))
(effectively, this causes the method call + args to be queued and later executed on the correct event queue).
Is there a way to use method references instead of using the method name as string (i.e. use &MyClass::myMethod
instead of "myMethod"
), while still queueing execution?
Upvotes: 0
Views: 407
Reputation: 5472
Since Qt 5.10 there are two QMetaObject::invokeMethod overloads which accept functor or a pointer to a member function as an argument.
Inside the same thread you can use QTimer::singleShot overload accepting functor (since Qt 5.4) and use zero milliseconds timeout.
Upvotes: 1