This is not a Qt question per se, but a C++ question.
When you declare an object like this:
QWidget wid;
It is created on the stack and only has local scope, in other words when you get to the end of the function that declared it, it is destroyed. But normally for GUI elements, you want them to stick around, so you create them instead on the heap with "new" like this:
QWidget * wid = new QWidget();
Here you've created a new widget on the heap that will stick around until you specifically delete it, your only reference to it being a pointer variable. You use a pointer in this case because its often more efficient to store a pointer to an object instead of storing the object itself.
Bookmarks