Use callback style to start a worker thread and receive result in Qt After using JavaScript for a while, I think callbacks are pretty good for asynchronous programming, but I haven't seen anything similar in C++. What I want to achieve is to start a worker thread from a function/lambda, and then use a callback to receive the result, which will be run in the main thread. The callback is required to run in the main thread because Qt GUI code is limited to run there. asyncRun is a convenient function to achieve the above. Let me know what you think.

template &lt;typename AsyncFunc, typename Callback&gt;
void asyncRun(QObject* obj, AsyncFunc asyncFunc, Callback callback) {
    auto asyncFuncWrapper = [=]() {
        auto result = asyncFunc();
        QTimer::singleShot(0, obj, std::bind(callback, result));
    };
    QtConcurrent::run(asyncFuncWrapper);
}

// Convenient function to run the callback in the main thread.
template &lt;typename AsyncFunc, typename Callback&gt;
void asyncRun(AsyncFunc asyncFunc, Callback callback) {
    asyncRun(QCoreApplication::instance(), asyncFunc, callback);
}

// Example usages
asyncRun([]() {
    qDebug() &lt;&lt; "thread:" &lt;&lt; QThread::currentThreadId();
    QThread::msleep(500);
    return 666;
}, [=](int result) {
    qDebug() &lt;&lt; "thread:" &lt;&lt; QThread::currentThreadId() &lt;&lt; result;
});
This answer seems to be what you are looking for. I copy it here for reference:

There is this library that is highly integrated with Qt and implements javascript-like promises:

https://github.com/juangburgos/QDeferred

It allows to create a thread-safe async API as follows:

multiplyNumbersInThread(3, 4)
.fail([](int res) {
    Q_UNUSED(res);
    qDebug() &lt;&lt; "multiplyPositiveNumbers failed!";
})
.done([](int res) {
    qDebug() &lt;&lt; "multiplyPositiveNumbers succeded! Result :" &lt;&lt; res;
});