0

I've written a Qt application where I call a lot of constructors:

Object o = new Object(blabla);

and I can't delete them until the user closes the program.

When the close button is clicked (or cmd-Q) I call this function:

qApp->quit();

Now does this function delete all previous allocated memory, or do I have to do it myself manually? I've already looked in the documentation of the quit-function, but it doesn't mention it.

Mat
  • 202,337
  • 40
  • 393
  • 406
Tcanarchy
  • 760
  • 1
  • 8
  • 20
  • Are your objects all `QObject` instances? I ask because, in Qt, there is a special treatment of the destruction of class inheriting `QObject`. – lrineau Jan 07 '14 at 17:17
  • 2
    In addition to what M.C. said... in general Qt has a very interesting/clever scheme for memory management. Qt does a lot of memory management for you, particularly with the QObject parent pointers that are usually passed around as an argument in constructors. read more about it here on [stackoverflow](http://stackoverflow.com/questions/2491707/memory-management-in-qt) or [google it](https://www.google.com/search?q=qt+memory+mangement). – Son-Huy Pham Jan 07 '14 at 17:18

1 Answers1

0

that function stops the main thread's event loop and returns control back to the main function

if your main is:

int main(int argc, char *argv[]){
QApplication qApp(argc, argv);
MyQObject obj();


return qApp.exec();
}

then RAII will delete obj which will propagate down to the children

if you need to cleanup other resources then you can use qAddPostRoutine to add a cleanup function, these will be called from the qApp destructor

ratchet freak
  • 47,288
  • 5
  • 68
  • 106