Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-64510

QWidgetAction doesn't release widget

    XMLWordPrintable

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

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            richard Richard Moe Gustavsen
            kriston Andras Kriston
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes