You can delete them once you're done using them either by an explicit delete call or with deleteLater().
You can delete them once you're done using them either by an explicit delete call or with deleteLater().
Hi, thanks for your response.
In the requestFinished of the CNetworkManager class I invoke a callback from my CTest as I mentioned, e.g., like this:
Qt Code:
void CNetworkManager::requestFinished(QNetworkReply* reply) { //... this->ptCallBackCTest(ptObject, netResponse); // (*) we will get here - to line number 5 - after the callback finished execution right? So, if I delete here the CNetworkManager instance or "this" in other // words it means I am "killing myself" within my own function. //.. }To copy to clipboard, switch view to plain text mode
In other way, I could also pass a pointer to "this" (above code) to the callback function and try to delete it inside the CTest callback -- but in that
case I will never reach the 5th line as above -- and will not it cause crash??? Thanks.
I don't understand why you'd want to kill the manager when a request finishes. How do you know that no more requests are coming?
Because for each request I create a new CNetworkManager object (maybe this is not recommended but that is how it is now). So each one usually handles one request.
I don't mind. I am just not sure if it is ok. As it can be seen from my implementation the requestFinished is implemented as a member function of CNetworkManager:
So I was not sure if it is ok to call delete "this" as above? (e.g., in a member function). is it? Thanks.Qt Code:
void CNetworkManager::requestFinished(QNetworkReply* reply) { ... // Is it ok to call: "delete this" here?? // now we are in the instance created at line 3 of my initial Code snippet. }To copy to clipboard, switch view to plain text mode
Excuse me for jumping in, but is this a typical use case for deleteLater()? That is, a QObject instance must live long enough for it to be used in a slot or other method, at which point it can be deleted, and that deletion occurs the next time the event loop in which deleteLater() was called is entered?
What happens in the case where the signal that passes the instance pointer is handled by more than one slot? Does moving from one slot to the next count as a "return to the event loop"? Or is the invocation of all the connected slots happen within the scope of a single event, and only after all slots have been called is the instance deleted?
If the latter is the case, this is a pretty useful scenario for when stack-based instances won't work.
Bookmarks