[Interest] Lambda functions not reused by connect?
Alejandro Exojo
suy at badopi.org
Fri Apr 24 07:53:59 CEST 2015
El Thursday 23 April 2015, Alejandro Exojo escribió:
> Here I added a "static bool copy" that acts as a workaround to keep the
> state across invocations.
Which is only useful for the first connect call. If you are going to use it
multiple times is useless.
> I want the "if" block that prints "should only
> be seen once" to be called only once, but it doesn't. Is this intended? I
> suppose that since lambdas are on-the-fly classes, each signal emission
> creates a new instance of the class, instead of one instance and several
> calls to operator(). Is that so?
I've used a function object/functor instead, and yes, the copy constructor is
called twice on the connect() call, and once more for each signal emission.
> Another way to do it would be to let the lambda disconnect itself, but it
> is quite difficult to capture the return of connect().
Or a completely different approach, since for the general case a disconnect is
not enough. One might need a different path in the body of the function.
I think I'll create just a small QObject subclass specific for the task, so I
can control the intances myself, and self delete to destroy the connection, or
whatever I need. But, man, what a pity. With the lambda function it was much
simpler and clearer, IMHO.
--
Alex (a.k.a. suy) | GPG ID 0x0B8B0BC2
http://barnacity.net/ | http://disperso.net
More information about the Interest
mailing list