Should I disconnect the lambda from the signal in Qt5.5?

In earlier versions of Qt 5, I had to disconnect lambdas from signals, as shown here: " Disabling lambda functions in Qt5 ".

Here I found the following statement: Auto shutdown does not occur when the "receiver" is destroyed, because it is a functor without a QObject. However, starting with 5.2, there is an overload that adds a "context object". When this object is destroyed, the connection is interrupted (the context is also used for the affinity of the stream: the lambda will be called in the stream of the event loop of the object used as the context).

  • Does this mean that I no longer need to disable lambdas with Qt5.2 or later?
  • Should I pass this context or is it done automatically?
+5
source share
1 answer

Qt automatically removes all connections to or from an object when it is destroyed through QObject :: ~ QObject () . Therefore, if you create a connection to a lambda when the send object is deleted, the connection is automatically cleared. You do not have and did not need to disable it yourself before.

The context object that you are accessing is used when you need finer-grained control over the lifetime of a connection. This is used when you want the connection to be deleted when another object is destroyed (context object). This makes it easy to remove the connection if you need to do this before the sender is destroyed.

In short: you do not need to manually disable the lambda, they are automatically cleared. You can use context objects to remove a connection before destroying the sender object.

+6
source

Source: https://habr.com/ru/post/1234564/


All Articles