Bug in disconnect when using lambdas
-
Using this code:
@
obj->connect(sender, &Sender::signal, [] {
});// later
obj->deleteLater();
@The object will be deleted, but the connection will not be broken, and the sender can still signal, the lambda will be called, but of course it will crash. Is this a known limitation of using lambdas?
-
Hi,
Good question, I think you should ask it on the interest mailing list, you'll find Qt's developers/maintainers there (this forum is more user orienteD)
-
After read this: [https://medium.com/genymobile/how-c-lambda-expressions-can-improve-your-qt-code-8cd524f4ed9f#.52geilaqe](How C++ lambda expressions can improve your Qt code), you need to pass a context argument to connect:
obj->connect(sender, &Sender::signal, obj, [] {
-
it falls in the same category as
Lambdas do not work with Qt::UniqueConnection
found hereAlso:
@Wiki said in New Signal Slot Syntax:
//Section Disconnecting in Qt5
Only works if you connected with the symmetric call, with function pointers (Or you can also use 0 for wild card) In particular, does not work with static function, functors or lambda functions.
-> not automatic disconnects when deleting the sender.