自定义QHBoxLayout的布局,在析构时引发异常
Label = new QLabel(QString("AAAAA"));
ComboBox = new QComboBox;
SpacerItem = new QSpacerItem(200, 20, QSizePolicy::Fixed);
HBox_Layout = new QHBoxLayout;
HBox_Layout->addWidget(Label,0);
HBox_Layout->addWidget(ComboBox,1);
HBox_Layout->addSpacerItem(SpacerItem);
delete HBox_Layout;
delete Label;
delete ComboBox;
delete SpacerItem;//异常发生异常在这里
查找QHBoxLayout源码发现
/*!
Destroys this box layout.
The layout's widgets aren't destroyed.
*/
QHBoxLayout::~QHBoxLayout()
{
}
说明QHBoxLayout会自动析构QSpacerItem;
所以异常发生是因为析构冲突