title: How to best store data of dynamically created widgets in Qt
body: <p>I'm building a Qt application with VC++ and I need several long forms with various widgets. I'm trying to allocate these widgets dynamically to make the process of adding new pages much simpler. </p>
  
  <p>To do this, I'm passing a QStringList 'key' and QVector&lt;QString&gt; 'vec' into the QDialog that holds the form. The first character of key[i] holds the widget type and the rest holds the label. Each vec[i], on the other hand, needs to hold any corresponding information altered by the user (from the dynamically created widgets).</p>
  
  <p>So far, I've tried the following inside of a for loop (each loop goes through one key):</p>
  
  <pre><code>char typeVal = key[i].toStdString()[0]; // widget type
  key[i] = key[i].mid(1); // widget label
  
  switch (typeVal)
  {
      case 'e': // edit (lineedit)
      {
          QLineEdit *newEdit = new QLineEdit(page);
          connect(newEdit, &amp;QLineEdit::textChanged, [&amp;] {
              vec[vecIndex] = newEdit-&gt;text().toStdString(); });
          layout-&gt;addRow(key[i], newEdit);
          break;
      }
      // ...
  }
  </code></pre>
  
  <p>However, this gives me an 'access violation reading location' due to the newEdit->text(). This might be a problem with how I'm using the lambda function slot, as I don't know much about lambda declarations. If there's a fix for this, or if the whole process is needlessly convoluted and there's a better method of tracking the widget data, I'd love to hear it.</p>