How to execute a functor or a lambda in a given thread in Qt, GCD-style?(如何在 Qt、GCD 风格的给定线程中执行函子或 lambda?)
问题描述
在带有 GCD 的 ObjC 中,有一种方法可以在任何旋转事件循环的线程中执行 lambda.例如:
In ObjC with GCD, there is a way of executing a lambda in any of the threads that spin an event loop. For example:
dispatch_sync(dispatch_get_main_queue(), ^{ /* do sth */ });
或:
dispatch_async(dispatch_get_main_queue(), ^{ /* do sth */ });
它在主线程的队列中执行一些(相当于C++中的[]{/* do sth *