[Qt-interest] Should I delete the pointer ?
william.crocker at analog.com
william.crocker at analog.com
Sat Jan 15 14:26:45 CET 2011
>
> Hi ,all ,! I'm trouble in the issue :
>
> Should I delete the towers[4] ??
>
In any case, valgrind or Purify should be a part
of your tool kit. If you do try to delete something
when you should not, it will tell you.
My thought process (when Qt is in the mix)
goes like this:
if( I called new ) {
// You may have to call delete.
If( Object is now child of a controlled Qt object ) {
I do not have to call delete on child.
It is the parents responsibility.
} else {
I own the object and must call delete.
}
} else {
if( I got the object from a context like QLayout::takeAt
where I become responsible for deleting the returned
object ) {
I now own the object and must call delete.
} else {
No need to call delete.
}
}
> Code here :
> ---------------------
> class hanoi : public QWidget
>
> {
>
> Q_OBJECT
>
> public:
>
> /*explicit*/ hanoi(QWidget *parent = 0);
>
> void TowersOfHanoi(int n,int x,int y,int z);
>
> private:
>
> QStack<int> towers[4];
>
> signals:
>
> public slots:
>
> void ShowStatus();
>
> };
>
> ------------------
>
> --
> /Your biological and technological distinctiveness will be added to
> our own. Resistance is futile./
>
>
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com <mailto:Qt-interest at qt.nokia.com>
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
More information about the Qt-interest-old
mailing list