[Development] Evolving Qt's multithreading API

Sorvig Morten Morten.Sorvig at digia.com
Tue Mar 5 08:39:23 CET 2013


On Mar 4, 2013, at 11:56 PM, Thiago Macieira <thiago.macieira at intel.com> wrote:
> 
> Oh, and if you want simple, one more thing occurred to me:
> 
>  runFunction([]() { main(); then(); });
> 
> If you need the return value:
>  runFunction([]() { then(main()); });
> 
> I will not accept "C++11 isn't available for everyone" as a reason to add a 
> more complicated API. The API should be designed for C++11 use and later made 
> to work with C++98, with as little modification as possible.

I think this is the direction we should go in: build the future API around C++11 lambdas.

This reduces the need for QFuture and especially QFutureWatcher. Thiago pointed out the waiting case above. Instead of connecting to QFutureWatcher::finished(), create a signal and emit when the work is done:

MyObject::asyncWork()
{
    runFunction([]() { 
        Result result = doWork();
        emit done(result); // signal on MyObject
    });
}

Morten




More information about the Development mailing list