Results 1 to 6 of 6

Thread: When to delete QNetworkReply?

  1. #1
    Join Date
    Jul 2007
    Posts
    121
    Thanks
    38
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default When to delete QNetworkReply?

    Calling "post" on QNetworkAccessManager returns pointer to QNetworkReply that is later passed to a connected slot as a parameter.

    Questions:
    Who is responsible to deleting it ?
    If it should be deleted manually - where is the right place to do it?
    If it is managed by Qt - when it is deleted?

  2. #2
    Join Date
    May 2008
    Location
    Melbourne, Australia
    Posts
    136
    Thanks
    9
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: When to delete QNetworkReply?

    Currently I'm using the slot to clean up the memory (the QNetworkAccessManager and its children).
    But is the slot called in all cases? - including when the server has an error or times out.
    If not then I have a potential memory leek.

  3. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: When to delete QNetworkReply?

    From QNetworkAccessManager::~QNetworkAccessManager() docs:
    Destroys the QNetworkAccessManager object and frees up any resources. Note that QNetworkReply objects that are returned from this class have this object set as their parents, which means that they will be deleted along with it if you don't call QObject::setParent() on them.
    J-P Nurmi

  4. #4
    Join Date
    May 2008
    Location
    Melbourne, Australia
    Posts
    136
    Thanks
    9
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: When to delete QNetworkReply?

    yeah that's how I clean up the memory, with the QNetworkAccessManager destructor. I call it after the request because I'm relying on it's slot:
    http://doc.trolltech.com/4.4/qnetwor....html#finished

    But I'm not sure if the slot is called in all cases. My app has a lot of network activity so I don't want a memory leak here.

  5. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: When to delete QNetworkReply?

    Quote Originally Posted by rbp View Post
    yeah that's how I clean up the memory, with the QNetworkAccessManager destructor. I call it
    Do you mean that you call a destructor explicitly?
    J-P Nurmi

  6. #6
    Join Date
    May 2008
    Location
    Melbourne, Australia
    Posts
    136
    Thanks
    9
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: When to delete QNetworkReply?

    Do you mean that you call a destructor explicitly?
    No, indirectly:
    Qt Code:
    1. delete reply->manager();
    To copy to clipboard, switch view to plain text mode 

    Do you know if the slot is always called, including for errors and timeouts?
    I can clean up the memory fine if the slot is always called.

Similar Threads

  1. Best way for a graphicsitem to delete itself
    By pherthyl in forum Qt Programming
    Replies: 7
    Last Post: 22nd June 2008, 05:57
  2. Delete dialog
    By Krish_ng in forum Qt Programming
    Replies: 3
    Last Post: 9th August 2007, 12:42
  3. Deleting from TreeWidget... Memoryleak
    By VireX in forum Qt Programming
    Replies: 5
    Last Post: 1st June 2007, 21:33
  4. c++, placement delete upon exception
    By stinos in forum General Programming
    Replies: 6
    Last Post: 31st October 2006, 15:38
  5. QListWidget + Delete Key
    By bpetty in forum Newbie
    Replies: 5
    Last Post: 16th August 2006, 20:38

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.