#include <QApplication>#include <QWidget>#include <QVBoxLayout>int main(int argc, char *argv[]) { QApplication app(argc, argv);// It doesn't work: QVBoxLayout layout; QWidget widget; widget.setLayout(&layout); widget.show();// It works:// QWidget widget;// QVBoxLayout layout;// widget.setLayout(&layout); // widget.show();// It works:// QWidget *widget = new QWidget;// QVBoxLayout *layout = new QVBoxLayout;// widget->setLayout(layout); // widget->show();// It works:// QVBoxLayout *layout = new QVBoxLayout;// QWidget *widget = new QWidget;// widget->setLayout(layout); // widget->show(); return app.exec();}
delete widget;delete layout;