c++ - When to delete QNetworkAccessManager pointer? -


This is my code but I am confused that where should I delete m_networkManager ?

My fear is this:

  1. I can do this onRequestCompleted () slot but the problem is that my program The call getData function is often.
    1. Call Code> getData () is called.
    2. onRequestCompleted () before the slot has been removed, my program call getData () again.
    3. onRequestCompleted () is removed for the first getData () call.
    4. My program deletes m_networkManager which was originally allocated to memory when getData () was called the second time.

      I think the cause of this situation can be the accident. Zero MyApp :: getData () {QNetworkRequest request; Request.setUrl (QUrl ("http://www.domain.foo")); M_networkManager = New QNetworkAccessManager (this); // Instant Variable Connect (m_networkManager, Signal (Finish (QN NetworkCare *)), This Slot (On-Vinium (QN NetworkCar * *)); M_networkManager- & gt; Received (request); } Zero MyApp :: onRequestCompleted (QNetworkReply * Answer) {QByteArray Data = Answer-> readAll (); reply-> deleteLater (); // m_networkManager-> deleteLater (); }

      Since you create a new QNetworkAccessManager example every time As the MyApp :: getData () is called , you have to manage the removal of the correct one in the :: MyApp :: onRequestCompleted () function. The problem with your code is that you always delete the last built QNetworkAccessManager and not because of that slot call. My suggestion is the following:

        zero MyApp :: getData () {[..] // will not be removed in square member slot QNetworkAccessManager * Network Manager = New QNetworkAccessManager (this); Connect (m_networkManager, Signal (Finished (QN NetworkCarP *)), This Slot (HonorConstructed Compliant (QN NetworkCar * *)); [..]} Zero MyApp :: onRequestCompleted (QNetworkReply * Answer) {QByteArray Data = Answer-> readAll (); reply-> deleteLater (); // Delete the object whose signal triggers this slot QObject * Network Manager = Sender (); networkManager- & gt; deleteLater (); }    

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

c# - passing input text from view to contoller with FacebookContext using Facebook app -

Calling a C++ function from C# by passing a string with variable size to it -