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

Missing documentation that QLayout constructor sets parent layout

    XMLWordPrintable

    Details

    • Commits:
      cd499b72973a4a01d12e2e3ba66e7e16ac1feeb4

      Description

      The constructor of QLayout sets the parent widget's layout to 'this' (see here). The bug is that this behavior is not documented. For example here:

      http://doc.qt.io/qt-5/qlayout.html#QLayout

      The "Basic Layouts Example" page does not mention why it creates Layouts without parent widgets, either:

      http://doc.qt.io/qt-5/qtwidgets-layouts-basiclayouts-example.html

       

       This can lead to a difficult to debug warning:

      QWidget::setLayout: Attempting to set QLayout "" on Widget "", which already has a layout
      

       when the following happens:

      • Creating a layout not intended for widget A with it as parent (to avoid a potential memory leak):
      QVBoxLayout *mainLayout = new QVBoxLayout(A);
      
      • And giving that widget another layout later:
      A->setLayout(anotherLayout);
      

       

      For an example of this affecting users in the wild, see for example:

      https://stackoverflow.com/questions/10519006/qwidgetsetlayout-attempting-to-set-qlayout-on-widget-which-already-has

      https://gitlab.orfeo-toolbox.org/orfeotoolbox/otb/merge_requests/187

       

       

       

        Attachments

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

          Activity

            People

            Assignee:
            chehrlic Christian Ehrlicher
            Reporter:
            victorpoughon Victor Poughon
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Gerrit Reviews

                There are no open Gerrit changes