While trying to understand the difference between creating widgets on the stack or the heap, I came across this behaviour that puzzles me regarding layouts:
int main(int argc, char *argv[]){
QApplication app(argc, argv);
QWidget win;
QVBoxLayout layout(&win);
This will work fine. Then, while trying to invert the order of creation to see what would happen when the objects go out of scope, this happened:
int main(int argc, char *argv[]){
QApplication app(argc, argv);
QVBoxLayout layout;
QWidget win;
layout.setParent(&win);
I was expecting some crash due to win trying to delete the stack created layout, but instead this is what I got:
QLayout:arentWidget: A layout can only have another layout as a parent.
But in the version, isn't the layout being created with the QWidget as parent? I expected a crash when the destructor got called, but not this... can someone explain this to me?
Thank you!
Newbie.
Bookmarks