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

Alejandro Exojo alex at vikingsoft.eu
Wed Aug 9 23:19:32 CEST 2017

On Wednesday 09 August 2017 18:04:16 Nikos Chantziaras wrote:
> 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?

I wrote about something closely related to this a while ago in this list, and 
some time after that, I mentioned the issue to Olivier Goffar, and he was 
quite kind (and quick!) to fix it.

My problem back at that time, was that the lambda was being copied each time 
the signal was emitted (not just on connect()), which made mutable lambdas 
quite useless. This was fixed here:


If you check the added unit test, it seems that not only they are aware, but 
are verifying that the copy on connect happens:

QCOMPARE(emit o.returnInt(0), 1);
QCOMPARE(emit o.returnInt(0), 2); // each emit should increase the internal 

QCOMPARE(functor.count, 0); // but the original object should have been copied 
at connect time

Viking Software, Qt and C++ developers for hire

More information about the Interest mailing list