PDA

View Full Version : Resource dispose in Qt4



tpieciak
12th September 2010, 16:39
Hi,

Could someone explain me, why in the official Qt4 documentation, there is no delete operators?

Is garbage collector build in Qt4?


For example, QAction objects are created by new operator, and there are no deconstructor (delete operations).

http://doc.trolltech.com/4.7-snapshot/mainwindows-application.html

Is the reason is to be clean code?

Zlatomir
12th September 2010, 16:45
There is no garbage collector

But there is parent-child (http://doc.qt.nokia.com/4.6/objecttrees.html) relationship, objects are organized in hierarchies, and the parent will delete the child when gets out of scope (if created on stack) or manually deleted (if it was created on heap)

tpieciak
12th September 2010, 22:12
Thank you Zlatomir,

So, in Qt4 I needn't use shared_ptr class from Boost library, is it?

Zlatomir
12th September 2010, 22:17
Qt has its own shared pointer (http://doc.trolltech.com/4.6/qsharedpointer.html), so you can use that.

And note that only the classes witch derive from QObject have the "parenting" thing, the other (even if their name starts with the letter 'Q') don't have that, so if you allocate on heap you must delete.

tpieciak
13th September 2010, 00:51
Sorry, post to trash.