Details
-
Bug
-
Resolution: Invalid
-
Not Evaluated
-
None
-
5.9.1
-
None
-
Ubuntu 16.04
Description
QtWidgetAction::releaseWidget doesn't really release the widget.
For example:
Adding a widget with QToolBar::addWidget creates a new QWidgetAction for the widget. Now the ownership is transferred the QWidgetAction. However there is now way to recover the widget without destroying it. Widget's setparent is ignored, QToolBar will destroy the widget on destruction. Calling QtWidgetAction::releaseWidget on the specific widget before destroying the toolbar doesn't help as it does not release the widget, just hides it and sets its parent to null, but doesn't set the member pointer to null. It is still deleted on QtWidgetAction's destruction.
example code 1:
QWidget* w = new QWidget();
QToolBar* tb = new QToolBar();
QWidgetAction* wa = static_cast<QWidgetAction*>(tb->addWidget(w));
wa->releaseWidget(w); //w's parent is null
delete tb; //w is now invalid
example code 2:
QWidget* w = new QWidget();
QToolBar* tb = new QToolBar();
tb->addWidget(w);
w->setParent(otherWidget);
delete tb; //w is now invalid