Greetings. This is more of a C++ question, but I'm posting it here because I would like to know how it relates to Qt.

Reading books on Qt, I know that widgets should be constructed on the heap because they will be deleted automatically when their parents are deleted. My question is this: if I have a custom widget class and I instantiate it on the heap, would the members also go on the heap even though they are not dynamically created in the class?

Qt Code:
  1. class MyWidget : public QWidget{
  2.  
  3. private:
  4. QPushButton myButton_;
  5. };
  6.  
  7. ...
  8.  
  9. MyWidget *w = new MyWidget;
To copy to clipboard, switch view to plain text mode 

In the example code does 'myButton_' reside on the heap or the stack? Printing the memory address it seems that it's on the heap. Does this mean that I can avoid using the 'new' operator and dynamic memory allocation for members of my class if I know for sure that the class will be constructed on the heap?

or is it always best to use pointers regardless?
Qt Code:
  1. class MyWidget : public QWidget{
  2.  
  3. public:
  4. MyWidget(){
  5. pMyButton_ = new QPushButton;
  6. }
  7.  
  8. ~MyWidget(){
  9. delete pMyButton_;
  10. }
  11. private:
  12. QPushButton *pMyButton_;
  13. };
  14.  
  15. ...
  16.  
  17. MyWidget *w = new MyWidget;
To copy to clipboard, switch view to plain text mode