While working in QML, I'm incorporating a C++ library that produces a QObject responsible for executing a process and triggering a signal upon completion. To handle this signal in JavaScript, I utilize the connect
method of the emitted signal (success
) to attach an anonymous function as demonstrated in the code snippet below:
var requestResponse = apiClient.execute(reqInp);
requestResponse.success.connect(function success(response)
{
var requestResponseJSON = JSON.parse(response.responseAsJsonString());
this.append(response.responseAsJsonString());
});
A challenge arises when the QML item containing this method is removed before the C++ logic can finish execution. Consequently, when the signal is triggered, the anonymous function encounters errors due to calling methods that are now undefined (such as the append
method in this case). This issue has led to some undesirable crashes on iOS devices, suggesting a possible correlation.
Is there a way to forcibly disconnect the signal when the object responsible for creating the function is destroyed?