title: How do you get text from dynamically created QLineEdit in a QToolBox?
body: <p>I am trying to make a variable number of pages on a QToolbox with a set number of QLineEdit fields. The number of pages and their names is determined by a vector of strings. Each page of the QToolbox has two QLineEdits. After the fillToolbox function is called, the printExtractedData function is called. As stated in the name I am just looking to print the std::string form of the data.</p>
  
  <pre><code>void fillToolbox(vector &lt;string&gt; toolboxLabels){
      QLineEdit *l1, *l2;
      QGridLayout *gridLayout;
      for (int i = 0; i &lt; numEntries; i++)
      {
          gridLayout = new QGridLayout;
          l1 = new QLineEdit;
          l2 = new QLineEdit;
          QFrame *frm = new QFrame;
          QLabel *l1Label = new QLabel("Field 1:");
          QLabel *l2Label = new QLabel("Field 2:");
          gridLayout-&gt;addWidget(l1Label, 0, 0);
          gridLayout-&gt;addWidget(l1, 0, 1);
          gridLayout-&gt;addWidget(l2Label, 1, 0);
          gridLayout-&gt;addWidget(l2, 1, 1);
          frm-&gt;setLayout(gridLayout);
          ui.myToolBox-&gt;addItem(frm, QString(toolboxLabels[i].c_str()));
      }
  }
  </code></pre>
  
  <p>User adds input to LineEdit fields.</p>
  
  <pre><code>void printExtractedData() {
      int numPages = ui.myToolBox-&gt;count();
      cout &lt;&lt; numPages &lt;&lt; endl;
      for (int i = 0; i &lt; numPages; i++)
      {
          string key = ui.myToolBox-&gt;itemText(i).toLocal8Bit().constData();
          if (QWidget* wg = qobject_cast&lt;QWidget*&gt;(ui.myToolBox-&gt;widget(i))) {
              QLayout *layout = wg-&gt;layout();
              for (int j = 0; j &lt; layout-&gt;count(); j++)
              {
                  if (QLineEdit* le = qobject_cast&lt;QLineEdit*&gt;(layout-&gt;itemAt(j)-&gt;widget())) {
                      string text = le-&gt;text().toLocal8Bit().constData();
                      cout &lt;&lt; le &lt;&lt;endl;
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>When I insert a two element list, I receive the output:<br/>
  2<br/>
  00000245E5A77260<br/>
  00000245E5A76FE0<br/>
  00000245E5A0A510<br/>
  00000245E5B17540<br/>
  <br/><br/>
  The desired result is a printed string of the content from the QLineEdit fields.<br/>
  Any help or advice would be appreciated.</p>