On sábado, 15 de dezembro de 2012 02.53.58, Nikos Chantziaras wrote:
> Since it's now possible to use lambdas as slots:
>
> connect(sender, &SenderClass::connected, [this] () {
> this->doSomething();
> };
>
> I have to wonder what is supposed to happen when the object where the
> lambda appears gets destroyed. In this particular example, if the
> lambda executes, dereferencing 'this' is no longer valid.
>
> The documentation:
>
> http://qt-project.org/doc/qt-5.0/qtcore/qobject.html#connect-5
Note that connect() returns a QMetaObject::Connection object now and there's a
disconnect() overload that takes such an object.
Also note how connecting to a lambda changes the delivery behaviour during
destruction. That is:
connect(sender, SIGNAL(connected()), SLOT(doSomething));
versus your example. During the destruction of this class, delivery to
doSomething will be stopped due to the virtual table being destroyed, but the
lambdas won't. You may end up calling this->doSomething() when the class is no
longer valid.
--
Thiago Macieira - thiago.macieira (AT) intel.com
Software Architect - Intel Open Source Technology Center
signature.asc
Description: This is a digitally signed message part.
_______________________________________________ Interest mailing list [email protected] http://lists.qt-project.org/mailman/listinfo/interest
