O wow. I get it now! Thanks!
O wow. I get it now! Thanks!
Sorry I have to reopen this question:
I tried the code jpn suggested, the code worked fine, but the problem is still there.
Also for those widgets, for example, the initialization of them, the formal way is
Wedgit awedgit=new Wedgit(* parent); or awdgit=Wedgit(*parent);?
Then this means the parent, has to be a pointer when instantiated? '
Then that means in the Child class, I will have to declare some pointers to Widget (that is the parents) so that means the memory leak is not preventable?
You don't have to declare anything.
When "wgt" is destroyed so are all its child QObjects (the label being one of them). No memory leak and no pointers declared (and no dangling pointers).Qt Code:
public: lab->setText("TEST"); } }; int main(int argc, char **argv){ MyWidget wgt; wgt.show(); return app.exec(); }To copy to clipboard, switch view to plain text mode
![]()
![]()
What I meant was actually
say in your example,
the MyWedgit, it is a child of another wedgit(for example YourWedigt, then when we initialize a MyWedgit object we have to use a pointer to YourWedgit as the first parameter. (I tried use simply an object instead of a pointer, and the compiler complained, either saying I cannot access the private object, or says cannot convert an object to a pointer).
The case you were showing me with "this", as the tool tip told me before, "this" was a pointer itself.
I guess I have created a bit too many classes to call one from another?
hope I made myself clear... and hope what I just written isn't something stupid...
Actually never mind...the problem isn't that serious any more. As long as I wait until the QT evaluation warning panel disappear, and run my program, it doesn't show up any more.
Bookmarks