deleteLater of Custom Class
Hi
I am using Qt 4.8.7 on Windows.
Sample of some code
Code:
{
Q_OBJECT
public:
~MyWidget();
private:
};
{
}
MyWidgt::~MyWidgt()
{
p1->deleteLater();
p2->deleteLater();
}
int main(int argc, char*argv[])
{
MyWidgt *qq = new MyWidgt;
qq->deleteLater();
or delete qq;
}
Kindly tell me which is the best process...
qq->deleteLater();
or delete qq;
Re: deleteLater of Custom Class
Usually p1 and p2 would be children of MyWidget and thus be deleted by MyWidget anyway.
But if you have objects that need deleting like that, just "delete"
Cheers,
_
Re: deleteLater of Custom Class
Hi
If I do not delete p1 and p2 in destructor, simply qq->deleteLater(), can p1 and p2 as a child will automatically deleted, kindly confirm it. I have a lot of widget allocated in constructor, if I do not delete it individually and simply delete class's object using delete later then it would delete all or not. Kindly confirm it. I am confused..
Thanks
Santosh
Re: deleteLater of Custom Class
It depends if those other widgets, in your case those buttons, are children of another widget.
Usually that will be the case, i.e. the buttons are part of a widget, not stand-alone windows.
In your code snippet above they are not, but then again that is almost certainly not your real code.
Cheers,
_