See this post: Creating and releasing a Qt widget object
It is explained that if one Qt object has a parent element, it will be automatically deleted when the parent is destroyed.
In your code:
wdgtis a parent layoutbecause you did wdgt->setLayout(layout).wdgt frame, layout->addWidget(frame) layout parent wdgt. thuga, .
wdgt ( Qt, ).
, :
QWidget * wdgt = new QWidget(&app);
, wdgt app app.
:
int main(int argc, char *argv[])
{
...
int res = a.exec();
delete wdgt;
return res;
}
, fianlly, , :
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QWidget wdgt;
QVBoxLayout *layout = new QVBoxLayout;
QFrame * frame = new QFrame;
frame->setFrameStyle(QFrame::Panel | QFrame::Plain);
frame->setLineWidth(5);
layout->addWidget(frame);
wdgt.setLayout(layout);
wdgt.setFixedSize(800,600);
wdgt.show();
return a.exec();
}
, , QVBoxLayout *layout = new QVBoxLayout(wdgt), wdgt->setLayout(layout). , :
QVBoxLayout *layout = new QVBoxLayout(wdgt);
:
QVBoxLayout *layout = new QVBoxLayout;
wdgt->setLayout( layout );