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

QHBoxLayout crash with non-contiguous indexes of layout items

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • Not Evaluated
    • None
    • 6.2.2
    • Widgets: Layout
    • None
    • macOS

    Description

      When activating a layout which has been built with layout items, but with non-contiguous indexes, qt will crash.

      This issue includes a project that demonstrates the problem.

      The following source code illustrates the problem

      CustomWidget::CustomWidget(QWidget *parent)
          : QWidget{parent}
      {
          QHBoxLayout * l = new QHBoxLayout(this);
          l->setSpacing(0);
      
          // BUG: Without the following line, this code crashes in Qt6.
          // It does not crash in Qt5 and behaves as if there is a zero-size
          // empty space (much like the following line).
      
      //    l->insertSpacing(0,0);
      
          l->insertWidget(1, new QLabel("foo", this));
          l->insertWidget(2, new QLabel("bar", this));
      
          // this will crash
          QSize s = l->sizeHint();
      }
      

      You can see that the line l->insertSpacing(0,0); is commented out. Without that line, Qt5 handles it just fine and Qt6 crashes. Uncommenting the line will fix it for both versions.

      Attachments

        1. Qt6BoxLayoutCrash.zip
          4 kB
          Michael Bishop
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            mbishop Michael Bishop
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes