December 3, 2010

ravehanker ravehanker
Lab Rat
1 posts

Non-virtual destructor in QNetworkAccessManager

 

I’m subclassing QNetworkAccessManager to provide for a custom protocol as per http://doc.trolltech.com/qq/32/qq32-webkit-protocols.html and I see that the destructor for QNetworkAccessManager is non-virutal(http://doc.qt.nokia.com/4.7-snapshot/qnetworkaccessmanager.html#dtor.QNetworkAccessManager).
I can see that this will not work if do not set a parent for the object and hold a reference to it as a QNetworkAccessManager.
Will the object be destroyed properly if I set a parent to it? Does QObject’s destructor handle children with non-virtual destructors properly?

1 reply

December 3, 2010

Volker Volker
Robot Herder
5428 posts

QNetworkAccessManager inherits from QObject. The latter has marked it’s destructor as virtual, so subsequently the destructors of all derived classes are virtual too.

See FAQ 20.7 [parashift.com] of the C++ FAQ for an explanation.

The object will be destroyed properly when it has a parent.

 
  ‹‹ MacOS: how to run AppleScript script from a Qt app?      [Merged] Inheriting Ui::MainWindow to add QListWidgetItem to a give ListWidget ››

You must log in to post a reply. Not a member yet? Register here!