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

Segmentation Fault when using InsertWidget with too-large index

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P4: Low
    • None
    • 6.6.2
    • Widgets: Layout
    • None
    • All

    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

        For Gerrit Dashboard: QTBUG-130275
        # Subject Branch Project Status CR V

        Activity

          People

            chehrlic Christian Ehrlicher
            marmarta Marta Marczykowska-Górecka
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There is 1 open Gerrit change