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

Segmentation Fault when using InsertWidget with too-large index

    XMLWordPrintable

Details

    • All
    • 0f9062ec7 (dev), 3c0f08ab7 (6.9), f70803eef (6.8), 618a2050d (tqtc/lts-6.5)

    Description

      InsertWidget on a layout results in a segfault if index is too big. Minimal example:

      #include <QtWidgets>
      
      class MyDialog : public QDialog {
      public:
          MyDialog(QWidget *parent = nullptr) : QDialog(parent) {
              QVBoxLayout *layout_1 = new QVBoxLayout(this);
              layout_1->insertWidget(1, new QLabel("aaa", this));
          }
      };
      
      int main(int argc, char *argv[]) {
          QApplication qt_app(argc, argv);
      
          MyDialog window;
          window.show();
      
          return qt_app.exec();
      }
      

      It works correctly if index is 0. This is confusing, as documentation says: "Inserts widget at position index, with stretch factor stretch and alignment alignment. If index is negative, the widget is added at the end." , which does not suggest any restrictions on index. I think a segfault is a very ugly way of handling it, some sort of more descriptive error would make debugging much easier.

      Attachments

        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
            marmarta Marta Marczykowska-Górecka
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There is 1 open Gerrit change