[Interest] connect() is copying lambdas - can this be avoided?

Nikos Chantziaras realnc at gmail.com
Wed Aug 9 17:04:16 CEST 2017

It seems that connect() is copying its lambda parameter around. That 
means that if a lambda capture contains a non-copyable object, like a 
unique_ptr, connect() cannot be used:

       auto ptr = std::make_unique<int>(0);
       connect(this, &MyQObject::mySignal,
               [ptr = std::move(ptr)]() mutable { });

(This is just an example. In reality, ptr would manage something 

It's useful to have the lambda take ownership of ptr, but currently 
that's not possible and we have to resort to shared_ptr. (Which is not 
the end of the world, but still.)

Is this a problem the Qt project is aware of and the design is intended, 
or is this something that can be considered a defect?

More information about the Interest mailing list